Commit ae258b52 authored by Dimitrios Chalepakis's avatar Dimitrios Chalepakis
Browse files

SI-1962 Adressdaten einer Verdichtung werden nicht angezeigt, da PLZ fehlt...

SI-1962 Adressdaten einer Verdichtung werden nicht angezeigt, da PLZ fehlt oder Daten nicht einfach textlich angezeigt werden, wie sie sind.
parent 4f20da4f
......@@ -14,6 +14,4 @@ sonar.exclusions=**/model/*.java,**/viewmodel/*.java, **/RabbitMqConfig.java
sonar.tests=src/test
#sonar.test.inclusions=**/*.spec.ts
sonar.test.exclusions=**/model/**,**/viewmodel/**, **/RabbitMqConfig.java
#sonar.ts.tslintconfigpath=tslint.json
sonar.typescript.lcov.reportPaths=coverage/lcov.info
\ No newline at end of file
#sonar.ts.tslintconfigpath=tslint.json
\ No newline at end of file
......@@ -496,9 +496,7 @@ public class FailureInformationService {
setEarliestStartdate(listSubordinatedFailureInfos, condensedFailureInformation);
setLatestEnddate(listSubordinatedFailureInfos, condensedFailureInformation);
setExpectedReason(listSubordinatedFailureInfos, condensedFailureInformation);
setCity(listSubordinatedFailureInfos, condensedFailureInformation);
setStreet(listSubordinatedFailureInfos, condensedFailureInformation);
setDistrict(listSubordinatedFailureInfos, condensedFailureInformation);
setAddress(listSubordinatedFailureInfos, condensedFailureInformation);
setRadius(listSubordinatedFailureInfos, condensedFailureInformation);
......@@ -573,58 +571,44 @@ public class FailureInformationService {
}
private void setStreet(List<TblFailureInformation> listFailureInfos, TblFailureInformation condensedFailureInformation){
private void setAddress(List<TblFailureInformation> listFailureInfos, TblFailureInformation condensedFailureInformation){
String firstStreet = listFailureInfos.get(0).getStreet();
List<TblFailureInformation> filteredList = listFailureInfos
Optional<TblFailureInformation> firstCompleteFailureInformation = listFailureInfos
.stream()
.filter(f -> f.getStreet()!=null)
.filter(f -> f.getStreet().equals(firstStreet))
.collect(Collectors.toList());
.filter(f -> f.getPostcode() != null && f.getStreet() != null && f.getHousenumber() != null)
.findFirst();
if (listFailureInfos.size() == filteredList.size()) {
condensedFailureInformation.setStreet(firstStreet);
}
else{
condensedFailureInformation.setStreet(null);
}
}
if (!firstCompleteFailureInformation.isPresent()) {
setCondensedFailureInformationAddress(condensedFailureInformation, null);
} else {
String address = concatAddress(firstCompleteFailureInformation.get());
private void setDistrict(List<TblFailureInformation> listFailureInfos, TblFailureInformation condensedFailureInformation){
String firstDistrict = listFailureInfos.get(0).getDistrict();
List<TblFailureInformation> filteredList = listFailureInfos
.stream()
.filter(f -> f.getDistrict()!= null)
.filter(f -> f.getDistrict().equals(firstDistrict))
.collect(Collectors.toList());
List<TblFailureInformation> filteredList = listFailureInfos
.stream()
.filter(f -> f.getPostcode() != null && f.getStreet() != null && f.getHousenumber() != null)
.filter(f -> concatAddress(f).equals(address))
.collect(Collectors.toList());
if (listFailureInfos.size() == filteredList.size()) {
condensedFailureInformation.setDistrict(firstDistrict);
}
else{
condensedFailureInformation.setDistrict(null);
if (listFailureInfos.size() == filteredList.size()) {
setCondensedFailureInformationAddress(condensedFailureInformation, firstCompleteFailureInformation.get());
}
else{
setCondensedFailureInformationAddress(condensedFailureInformation, null);
}
}
}
private void setCity(List<TblFailureInformation> listFailureInfos, TblFailureInformation condensedFailureInformation){
String firstCity = listFailureInfos.get(0).getCity();
List<TblFailureInformation> filteredList = listFailureInfos
.stream()
.filter(f -> f.getCity() != null)
.filter(f -> f.getCity().equals(firstCity))
.collect(Collectors.toList());
private void setCondensedFailureInformationAddress(TblFailureInformation condensedFailureInformation, TblFailureInformation failureInformation) {
condensedFailureInformation.setPostcode(failureInformation != null ? failureInformation.getPostcode() : null);
condensedFailureInformation.setStreet(failureInformation != null ? failureInformation.getStreet() : null);
condensedFailureInformation.setHousenumber(failureInformation != null ? failureInformation.getHousenumber() : null);
condensedFailureInformation.setCity(failureInformation != null ? failureInformation.getCity() : null);
condensedFailureInformation.setDistrict(failureInformation != null ? failureInformation.getDistrict() : null);
}
if (listFailureInfos.size() == filteredList.size()) {
condensedFailureInformation.setCity(firstCity);
}
else{
condensedFailureInformation.setCity(null);
}
private String concatAddress(TblFailureInformation failureInformation) {
if (failureInformation == null) return null;
return failureInformation.getPostcode() + failureInformation.getStreet() + failureInformation.getHousenumber();
}
private void setExpectedReason(List<TblFailureInformation> listFailureInfos, TblFailureInformation condensedFailureInformation){
......
......@@ -70,9 +70,7 @@ import java.util.List;
import java.util.Optional;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyLong;
......@@ -672,7 +670,7 @@ public class FailureInformationServiceTest {
}
@Test
public void shouldCondenseFailureInformations_equalFailureInfos() {
public void shouldCondenseFailureInformations_equalFailureInfos_completeAddress() {
List uuidList = MockDataHelper.mockUuidList();
......@@ -705,6 +703,8 @@ public class FailureInformationServiceTest {
assertEquals(tblFailureInformation1.getStreet(), savedCondensedFailureInfoDto.getStreet());
assertEquals(tblFailureInformation1.getDistrict(), savedCondensedFailureInfoDto.getDistrict());
assertEquals(tblFailureInformation1.getCity(), savedCondensedFailureInfoDto.getCity());
assertEquals(tblFailureInformation1.getPostcode(), savedCondensedFailureInfoDto.getPostcode());
assertEquals(tblFailureInformation1.getHousenumber(), savedCondensedFailureInfoDto.getHousenumber());
assertEquals(tblFailureInformation1.getRefExpectedReason().getUuid(), savedCondensedFailureInfoDto.getExpectedReasonId());
assertEquals(tblFailureInformation1.getFailureEndPlanned(), savedCondensedFailureInfoDto.getFailureEndPlanned());
assertEquals(tblFailureInformation1.getFailureBegin(), savedCondensedFailureInfoDto.getFailureBegin());
......@@ -714,13 +714,56 @@ public class FailureInformationServiceTest {
}
@Test
public void shouldCondenseFailureInformations_differentFailureInfos() {
public void shouldCondenseFailureInformations_setAddressNull_equalFailureInfos_notCompleteAddress() {
List uuidList = MockDataHelper.mockUuidList();
//different failureInfos
TblFailureInformation tblFailureInformation1 = MockDataHelper.mockTblFailureInformationWithoutAddress();
TblFailureInformation tblFailureInformation2 = MockDataHelper.mockTblFailureInformationWithoutAddress();
TblFailureInformation tblFailureInformation3 = MockDataHelper.mockTblFailureInformationWithoutAddress();
List<TblFailureInformation> listFailureInfos = new ArrayList();
listFailureInfos.add(tblFailureInformation1);
listFailureInfos.add(tblFailureInformation2);
listFailureInfos.add(tblFailureInformation3);
RefStatus refStatus = MockDataHelper.mockRefStatusCreated();
when(failureInformationRepository.findByUuidIn(any(List.class))).thenReturn(listFailureInfos);
when(statusRepository.findById(anyLong())).thenReturn(Optional.of(refStatus));
when(statusRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(refStatus));
when(failureInformationRepository.save(any(TblFailureInformation.class)))
.then((Answer<TblFailureInformation>) invocation -> {
Object[] args = invocation.getArguments();
return (TblFailureInformation) args[0];
});
FailureInformationDto savedCondensedFailureInfoDto = failureInformationService.condenseFailureInfos(uuidList, Optional.empty());
assertNotNull(savedCondensedFailureInfoDto.getUuid());
assertEquals(1L, savedCondensedFailureInfoDto.getVersionNumber());
//TODO: status (2x) und radius überprüfen
assertNull(savedCondensedFailureInfoDto.getStreet());
assertNull(savedCondensedFailureInfoDto.getDistrict());
assertNull(savedCondensedFailureInfoDto.getCity());
assertNull(savedCondensedFailureInfoDto.getPostcode());
assertNull(savedCondensedFailureInfoDto.getHousenumber());
assertEquals(tblFailureInformation1.getRefExpectedReason().getUuid(), savedCondensedFailureInfoDto.getExpectedReasonId());
assertEquals(tblFailureInformation1.getFailureEndPlanned(), savedCondensedFailureInfoDto.getFailureEndPlanned());
assertEquals(tblFailureInformation1.getFailureBegin(), savedCondensedFailureInfoDto.getFailureBegin());
assertEquals(true, savedCondensedFailureInfoDto.getCondensed());
assertEquals(null, savedCondensedFailureInfoDto.getFailureInformationCondensedId());
}
@Test
public void shouldCondenseFailureInformations_setAddressNull_differentFailureInfos_differentPostcodeStreetHousenumber() {
List uuidList = MockDataHelper.mockUuidList();
//different failureInfos and different postcode, street and house number
TblFailureInformation tblFailureInformation1 = MockDataHelper.mockTblFailureInformation();
TblFailureInformation tblFailureInformation2 = MockDataHelper.mockTblFailureInformation();
TblFailureInformation tblFailureInformation3 = MockDataHelper.mockTblFailureInformation2();
TblStation tblStation = MockDataHelper.mockTblStation();
......@@ -741,7 +784,6 @@ public class FailureInformationServiceTest {
List<TblFailureInformation> listFailureInfos = new ArrayList();
listFailureInfos.add(tblFailureInformation1);
listFailureInfos.add(tblFailureInformation2);
listFailureInfos.add(tblFailureInformation3);
//different status
......@@ -764,9 +806,72 @@ public class FailureInformationServiceTest {
assertNotNull(savedCondensedFailureInfoDto.getUuid());
assertEquals(1L, savedCondensedFailureInfoDto.getVersionNumber());
//TODO: status (2x) und radius überprüfen
assertEquals(null, savedCondensedFailureInfoDto.getStreet());
assertEquals(null, savedCondensedFailureInfoDto.getDistrict());
assertEquals(null, savedCondensedFailureInfoDto.getCity());
assertNull(savedCondensedFailureInfoDto.getStreet());
assertNull(savedCondensedFailureInfoDto.getDistrict());
assertNull(savedCondensedFailureInfoDto.getCity());
assertNull(savedCondensedFailureInfoDto.getPostcode());
assertNull(savedCondensedFailureInfoDto.getCity());
assertEquals(tblFailureInformation1.getFailureBegin(), savedCondensedFailureInfoDto.getFailureBegin());
assertEquals(tblFailureInformation3.getFailureEndPlanned(), savedCondensedFailureInfoDto.getFailureEndPlanned());
assertEquals(true, savedCondensedFailureInfoDto.getCondensed());
assertEquals(null, savedCondensedFailureInfoDto.getFailureInformationCondensedId());
}
@Test
public void shouldCondenseFailureInformations_setAddressRight_differentFailureInfos_samePostcodeStreetHousenumber() {
List uuidList = MockDataHelper.mockUuidList();
//different failureInfos but same postcode, street and house number
TblFailureInformation tblFailureInformation1 = MockDataHelper.mockTblFailureInformation();
TblFailureInformation tblFailureInformation3 = MockDataHelper.mockTblFailureInformation3();
TblStation tblStation = MockDataHelper.mockTblStation();
List<TblAddress> addressList = MockDataHelper.mockTblAddressList();
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
try {
java.util.Date date1 = dateformat.parse("01/01/2020");
java.util.Date date2 = dateformat.parse("24/12/2024");
// set first startdate and last enddate
tblFailureInformation1.setFailureBegin(date1);
tblFailureInformation3.setFailureEndPlanned(date2);
}catch(Exception e){
log.error("Error in FailureInformationServiceTest: SimpleDateFormat.parse");
}
List<TblFailureInformation> listFailureInfos = new ArrayList();
listFailureInfos.add(tblFailureInformation1);
listFailureInfos.add(tblFailureInformation3);
//different status
RefStatus refStatus = MockDataHelper.mockRefStatusCreated();
RefStatus refStatus2 = MockDataHelper.mockRefStatus2();
when(statusRepository.findByUuid(any(UUID.class))).thenReturn(Optional.of(refStatus));
when(failureInformationRepository.findByUuidIn(any(List.class))).thenReturn(listFailureInfos);
when(statusRepository.findById(anyLong())).thenReturn(Optional.of(refStatus)).thenReturn(Optional.of(refStatus2));
when(failureInformationRepository.save(any(TblFailureInformation.class)))
.then((Answer<TblFailureInformation>) invocation -> {
Object[] args = invocation.getArguments();
return (TblFailureInformation) args[0];
});
when(stationRepository.findByStationId(anyString())).thenReturn(Optional.of(tblStation));
when(addressRepository.findByStationId(anyString())).thenReturn(addressList);
FailureInformationDto savedCondensedFailureInfoDto = failureInformationService.condenseFailureInfos(uuidList, Optional.empty());
assertNotNull(savedCondensedFailureInfoDto.getUuid());
assertEquals(1L, savedCondensedFailureInfoDto.getVersionNumber());
//TODO: status (2x) und radius überprüfen
assertEquals(tblFailureInformation1.getStreet(), savedCondensedFailureInfoDto.getStreet());
assertEquals(tblFailureInformation1.getDistrict(), savedCondensedFailureInfoDto.getDistrict());
assertEquals(tblFailureInformation1.getCity(), savedCondensedFailureInfoDto.getCity());
assertEquals(tblFailureInformation1.getPostcode(), savedCondensedFailureInfoDto.getPostcode());
assertEquals(tblFailureInformation1.getHousenumber(), savedCondensedFailureInfoDto.getHousenumber());
assertEquals(tblFailureInformation1.getFailureBegin(), savedCondensedFailureInfoDto.getFailureBegin());
assertEquals(tblFailureInformation3.getFailureEndPlanned(), savedCondensedFailureInfoDto.getFailureEndPlanned());
assertEquals(true, savedCondensedFailureInfoDto.getCondensed());
......
......@@ -107,6 +107,9 @@ public class MockDataHelper {
dto.setStreet("Budenweg");
dto.setDistrict("West");
dto.setCity("Waldau");
dto.setStreet("Dieselstr.");
dto.setHousenumber("54");
dto.setPostcode("71111");
dto.setStationId("224488-123bcd");
dto.setStationDescription("Trafo 25");
......@@ -173,6 +176,9 @@ public class MockDataHelper {
obj.setStreet("Budenweg");
obj.setDistrict("West");
obj.setCity("Waldau");
obj.setStreet("Dieselstr.");
obj.setHousenumber("54");
obj.setPostcode("71111");
obj.setStationId("224488-123bcd");
obj.setStationDescription("Trafo 25");
......@@ -226,6 +232,114 @@ public class MockDataHelper {
obj.setStreet("Hügelpfad");
obj.setDistrict("Süd");
obj.setCity("Schlumpfhausen");
obj.setStreet("Benzinstr.");
obj.setHousenumber("1");
obj.setPostcode("81111");
obj.setStationId("44444-123bcd");
obj.setStationDescription("Trafo 11");
obj.setStationCoords("101,2222");
obj.setLongitude(BigDecimal.valueOf(12.646280));
obj.setLatitude(BigDecimal.valueOf(51.115618));
obj.setRefRadius(mockRefRadius());
obj.setPublicationStatus("neu");
obj.setPublicationFreetext("Korrodiertes Kabel");
obj.setRefExpectedReason(mockRefExpectedReason());
obj.setCreateDate(new java.util.Date(Date.valueOf("2021-05-11").getTime()));
obj.setCreateUser("roggensackl");
obj.setModDate(new java.util.Date(Date.valueOf("2020-05-12").getTime()));
obj.setModUser("müllers");
obj.setRefStatusIntern(mockRefStatus2());
obj.setRefFailureClassification(mockRefFailureClassification());
obj.setRefBranch(mockRefBranch());
obj.setRefStatusIntern(mockRefStatusCreated());
obj.setStations(mockTblStationList().stream().collect(Collectors.toList()));
return obj;
}
public static TblFailureInformation mockTblFailureInformation3() {
TblFailureInformation obj = new TblFailureInformation();
obj.setId(22L);
obj.setUuid(UUID.randomUUID());
obj.setVersionNumber(4L);
obj.setResponsibility("Vatter Mousa");
obj.setVoltageLevel(Constants.VOLTAGE_LEVEL_NS);
obj.setPressureLevel(Constants.PRESSURE_LEVEL_MD);
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
try {
java.util.Date date1 = dateformat.parse("04/12/2022");
java.util.Date date2 = dateformat.parse("05/12/2022");
java.util.Date date3 = dateformat.parse("06/12/2022");
obj.setFailureBegin(date1);
obj.setFailureEndPlanned(date2);
obj.setFailureEndResupplied(date3);
}
catch(Exception e){
log.warn("Fehler beim Erstellen von Daten mit DateFormat");
}
obj.setStreet("Budenweg");
obj.setDistrict("West");
obj.setCity("Waldau");
obj.setStreet("Dieselstr.");
obj.setHousenumber("54");
obj.setPostcode("71111");
obj.setStationId("224488-123bcd");
obj.setStationDescription("Trafo 25");
obj.setStationCoords("121,8855");
obj.setLongitude(BigDecimal.valueOf(8.646280));
obj.setLatitude(BigDecimal.valueOf(50.115618));
obj.setRefRadius(mockRefRadius());
obj.setPublicationStatus("veröffentlicht");
obj.setPublicationFreetext("Kabel aus Steckdose gerissen");
obj.setRefExpectedReason(mockRefExpectedReason());
obj.setCreateDate(new java.util.Date(Date.valueOf("2020-05-08").getTime()));
obj.setCreateUser("weizenkeimk");
obj.setModDate(new java.util.Date(Date.valueOf("2020-05-23").getTime()));
obj.setModUser("schlonzh");
obj.setRefStatusIntern(mockRefStatusCreated());
obj.setRefFailureClassification(mockRefFailureClassification());
obj.setRefBranch(mockRefBranch());
obj.setStations(mockTblStationList().stream().collect(Collectors.toList()));
return obj;
}
public static TblFailureInformation mockTblFailureInformationWithoutAddress() {
TblFailureInformation obj = new TblFailureInformation();
obj.setId(42L);
obj.setUuid(UUID.randomUUID());
obj.setVersionNumber(2L);
obj.setResponsibility("Schlumpfine");
obj.setVoltageLevel(Constants.VOLTAGE_LEVEL_HS);
obj.setPressureLevel(Constants.PRESSURE_LEVEL_MD);
SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
try {
java.util.Date date1 = dateformat.parse("12/08/2022");
java.util.Date date2 = dateformat.parse("02/09/2022");
java.util.Date date3 = dateformat.parse("02/09/2022");
obj.setFailureBegin(date1);
obj.setFailureEndPlanned(date2);
obj.setFailureEndResupplied(date3);
}
catch(Exception e){
log.warn("Fehler beim Erstellen von Daten mit DateFormat");
}
obj.setStationId("44444-123bcd");
obj.setStationDescription("Trafo 11");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment