Commit 2887f3a4 authored by dietricf's avatar dietricf
Browse files

SI-2877 Fix bei Verdichtung von Adressen (Refactoring)

parent c07472db
......@@ -70,24 +70,16 @@ import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static org.eclipse.openk.gridfailureinformation.constants.Constants.FREETEXT_ADDRESS_TYPE;
@Log4j2
@Service
public class FailureInformationService {
......@@ -588,13 +580,8 @@ public class FailureInformationService {
resetCondensedFailureInformationAdress(condensedFailureInformation);
setCityForCondensedFailureInformation(listFailureInfos, condensedFailureInformation);
setDistrictForCondensedFailureInformation(listFailureInfos, condensedFailureInformation);
setPostcodeForCondensedFailureInformation(listFailureInfos, condensedFailureInformation);
setStreetForCondensedFailureInformation(listFailureInfos, condensedFailureInformation);
setHousenumberForCondensedFailureInformation(listFailureInfos, condensedFailureInformation);
setCondensedFailureInformationCoordinates(listFailureInfos, condensedFailureInformation);
setCondensedFailureInformationAddresstype(listFailureInfos, condensedFailureInformation);
setAddressForCondensedFailureInformation(listFailureInfos, condensedFailureInformation);
}
private void resetCondensedFailureInformationAdress(TblFailureInformation condensedFailureInformation) {
......@@ -608,8 +595,8 @@ public class FailureInformationService {
condensedFailureInformation.setAddressType(null);
}
private void setCityForCondensedFailureInformation(List<TblFailureInformation> listFailureInfos,
TblFailureInformation condensedFailureInformation) {
private void setAddressForCondensedFailureInformation(List<TblFailureInformation> listFailureInfos,
TblFailureInformation condensedFailureInformation) {
Optional<TblFailureInformation> tblInfTocheck =
listFailureInfos.stream().filter(f -> (f.getCity() != null)).findFirst();
if (tblInfTocheck.isPresent()) {
......@@ -617,62 +604,23 @@ public class FailureInformationService {
listFailureInfos.stream().filter(p -> tblInfTocheck.get().getCity().equals(p.getCity())).count();
if (count == listFailureInfos.size()) {
condensedFailureInformation.setCity(tblInfTocheck.get().getCity());
}
}
}
private void setDistrictForCondensedFailureInformation(List<TblFailureInformation> listFailureInfos,
TblFailureInformation condensedFailureInformation) {
Optional<TblFailureInformation> tblInfTocheck =
listFailureInfos.stream().filter(f -> (f.getDistrict() != null)).findFirst();
if (tblInfTocheck.isPresent()) {
long count =
listFailureInfos.stream().filter(p -> tblInfTocheck.get().getDistrict().equals(p.getDistrict())).count();
if (count == listFailureInfos.size()) {
condensedFailureInformation.setDistrict(tblInfTocheck.get().getDistrict());
}
}
}
private void setPostcodeForCondensedFailureInformation(List<TblFailureInformation> listFailureInfos,
TblFailureInformation condensedFailureInformation) {
Optional<TblFailureInformation> tblInfTocheck =
listFailureInfos.stream().filter(f -> (f.getPostcode() != null)).findFirst();
if (tblInfTocheck.isPresent()) {
long count =
listFailureInfos.stream().filter(p -> tblInfTocheck.get().getPostcode().equals(p.getPostcode())).count();
if (count == listFailureInfos.size()) {
condensedFailureInformation.setPostcode(tblInfTocheck.get().getPostcode());
}
}
}
private void setStreetForCondensedFailureInformation(List<TblFailureInformation> listFailureInfos,
TblFailureInformation condensedFailureInformation) {
Optional<TblFailureInformation> tblInfTocheck =
listFailureInfos.stream().filter(f -> (f.getStreet() != null)).findFirst();
if (tblInfTocheck.isPresent()) {
long count =
listFailureInfos.stream().filter(p -> tblInfTocheck.get().getStreet().equals(p.getStreet())).count();
if (count == listFailureInfos.size()) {
condensedFailureInformation.setStreet(tblInfTocheck.get().getStreet());
}
}
}
private void setHousenumberForCondensedFailureInformation(List<TblFailureInformation> listFailureInfos,
TblFailureInformation condensedFailureInformation) {
Optional<TblFailureInformation> tblInfTocheck =
listFailureInfos.stream().filter(f -> (f.getHousenumber() != null)).findFirst();
if (tblInfTocheck.isPresent()) {
long count =
listFailureInfos.stream().filter(p -> tblInfTocheck.get().getHousenumber().equals(p.getHousenumber())).count();
if (count == listFailureInfos.size()) {
condensedFailureInformation.setHousenumber(tblInfTocheck.get().getHousenumber());
condensedFailureInformation.setLongitude(tblInfTocheck.get().getLongitude());
condensedFailureInformation.setLatitude(tblInfTocheck.get().getLatitude());
condensedFailureInformation.setAddressType(tblInfTocheck.get().getAddressType());
}
}
else {
// There is not info in the list having at least a city
// ... so try at least to merge the coordinates
setCondensedFailureInformationCoordinates( listFailureInfos, condensedFailureInformation);
}
}
//set first found coordinates if there is no consense at all
private void setCondensedFailureInformationCoordinates(List<TblFailureInformation> listFailureInfos, TblFailureInformation condensedFailureInformation) {
Optional<TblFailureInformation> firstFailureInformationFiltered = listFailureInfos
......@@ -684,14 +632,6 @@ public class FailureInformationService {
}
}
private void setCondensedFailureInformationAddresstype(List<TblFailureInformation> listFailureInfos, TblFailureInformation condensedFailureInformation) {
Optional<TblFailureInformation> firstFailureInformationFiltered = listFailureInfos
.stream().filter(f -> (FREETEXT_ADDRESS_TYPE.equals(f.getAddressType()))).findFirst();
if (firstFailureInformationFiltered.isPresent()) {
condensedFailureInformation.setAddressType(FREETEXT_ADDRESS_TYPE);
}
}
private void setExpectedReason(List<TblFailureInformation> listFailureInfos, TblFailureInformation condensedFailureInformation){
RefExpectedReason firstExpReason = listFailureInfos.get(0).getRefExpectedReason();
......
......@@ -822,12 +822,11 @@ class FailureInformationServiceTest {
assertNull(savedCondensedFailureInfoDto.getDistrict());
assertNull(savedCondensedFailureInfoDto.getCity());
assertNull(savedCondensedFailureInfoDto.getPostcode());
assertNull(savedCondensedFailureInfoDto.getCity());
assertNull(savedCondensedFailureInfoDto.getFreetextCity());
assertNull(savedCondensedFailureInfoDto.getFreetextDistrict());
assertNull(savedCondensedFailureInfoDto.getFreetextPostcode());
assertNotNull(savedCondensedFailureInfoDto.getLatitude());
assertNotNull(savedCondensedFailureInfoDto.getLongitude());
assertNull(savedCondensedFailureInfoDto.getLatitude());
assertNull(savedCondensedFailureInfoDto.getLongitude());
assertEquals(tblFailureInformation1.getFailureBegin(), savedCondensedFailureInfoDto.getFailureBegin());
assertEquals(tblFailureInformation3.getFailureEndPlanned(), savedCondensedFailureInfoDto.getFailureEndPlanned());
assertEquals(true, savedCondensedFailureInfoDto.getCondensed());
......
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