Skip to content

Commit

Permalink
fix: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Aug 2, 2024
1 parent 1ba63f7 commit 79e1f31
Showing 1 changed file with 1 addition and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,12 @@ public LinkedHashMap<CompanySiteDto, List<Polygon>> fetchPolygonDtos(List<Compan
return companySiteDtos.stream()
.map(myCs -> Map.entry(myCs, findPolygons(polygons, myCs.getId())))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> {throw new RuntimeException();}, LinkedHashMap::new));
}

public LinkedHashMap<Long, List<Polygon>> fetchPolygonEntitys(List<CompanySite> companySites) {
List<Polygon> polygons = this.polygonRepository
.findAllByCompanySiteIds(companySites.stream().map(myDto -> myDto.getId()).toList())
.stream().peek(this.entityManager::detach).toList();
return companySites.stream()
.map(myCs -> Map.entry(myCs.getId(), findPolygons(polygons, myCs.getId())))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> {throw new RuntimeException();}, LinkedHashMap::new));
}
}

private List<Polygon> findPolygons(List<Polygon> polygons, Long myCsId) {
return polygons.stream().filter(myPolygon -> myPolygon.getCompanySite().getId().equals(myCsId)).toList();
}

private <T extends BaseEntity> T findEntity(List<T> companySites, Long myCsId) {
return companySites.stream().filter(myCs -> myCs.getId().equals(myCsId)).findFirst().orElseThrow();
}

public LinkedHashMap<PolygonDto, List<Ring>> fetchRingDtos(List<PolygonDto> polygonDtos) {
List<Ring> rings = this.ringRepository
.findAllByPolygonIds(polygonDtos.stream().map(PolygonDto::getId).collect(Collectors.toList())).stream()
Expand All @@ -179,29 +166,11 @@ public LinkedHashMap<RingDto, List<Location>> fetchLocationDtos(List<RingDto> ri
.map(myRi -> Map.entry(myRi, findLocations(locations, myRi.getId())))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> {throw new RuntimeException();}, LinkedHashMap::new));
}

public Map<Long, List<Ring>> fetchRings(List<Polygon> polygons) {
List<Ring> rings = this.ringRepository
.findAllByPolygonIds(polygons.stream().map(Polygon::getId).collect(Collectors.toList())).stream()
.peek(this.entityManager::detach).toList();
return polygons.stream().map(Polygon::getId)
.map(myPgId -> Map.entry(this.findEntity(polygons, myPgId).getId(), findRings(rings, myPgId)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

private List<Ring> findRings(List<Ring> rings, Long myPgId) {
return rings.stream().filter(myRing -> myRing.getPolygon().getId().equals(myPgId)).collect(Collectors.toList());
}

public Map<Long, List<Location>> fetchLocations(List<Ring> rings) {
List<Location> locations = this.locationRepository
.findAllByRingIds(rings.stream().map(Ring::getId).collect(Collectors.toList())).stream()
.peek(this.entityManager::detach).toList();
return rings.stream().map(Ring::getId)
.map(myRiId -> Map.entry(this.findEntity(rings, myRiId).getId(), findLocations(locations, myRiId)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

private List<Location> findLocations(List<Location> locations, Long myRiId) {
return locations.stream().filter(myLocation -> myLocation.getRing().getId().equals(myRiId))
.sorted((a,b) -> a.getOrderId().compareTo(b.getOrderId()))
Expand Down

0 comments on commit 79e1f31

Please sign in to comment.