diff --git a/backend/src/main/java/ch/xxx/maps/adapter/controller/CompanySiteController.java b/backend/src/main/java/ch/xxx/maps/adapter/controller/CompanySiteController.java index 48a71a8..8d7b1af 100644 --- a/backend/src/main/java/ch/xxx/maps/adapter/controller/CompanySiteController.java +++ b/backend/src/main/java/ch/xxx/maps/adapter/controller/CompanySiteController.java @@ -18,7 +18,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.context.ApplicationContext; import org.springframework.graphql.data.method.annotation.Argument; import org.springframework.graphql.data.method.annotation.BatchMapping; import org.springframework.graphql.data.method.annotation.MutationMapping; @@ -31,30 +30,22 @@ import ch.xxx.maps.domain.model.dto.PolygonDto; import ch.xxx.maps.domain.model.dto.RingDto; import ch.xxx.maps.domain.model.entity.CompanySite; -import ch.xxx.maps.domain.model.entity.CompanySiteRepository; -import ch.xxx.maps.domain.model.entity.LocationRepository; -import ch.xxx.maps.domain.model.entity.PolygonRepository; -import ch.xxx.maps.domain.model.entity.RingRepository; import ch.xxx.maps.usecase.mapper.EntityDtoMapper; import ch.xxx.maps.usecase.service.CompanySiteService; import graphql.schema.DataFetchingEnvironment; -import jakarta.persistence.EntityManager; @Controller public class CompanySiteController { private static final Logger LOGGER = LoggerFactory.getLogger(CompanySite.class); private final CompanySiteService companySiteService; private final EntityDtoMapper entityDtoMapper; - private final ApplicationContext applicationContext; private record Selections(boolean withPolygons, boolean withRings, boolean withLocations) { } - public CompanySiteController(CompanySiteService companySiteService, EntityDtoMapper entityDtoMapper, - ApplicationContext applicationContext) { + public CompanySiteController(CompanySiteService companySiteService, EntityDtoMapper entityDtoMapper) { this.companySiteService = companySiteService; this.entityDtoMapper = entityDtoMapper; - this.applicationContext = applicationContext; } @QueryMapping diff --git a/backend/src/main/java/ch/xxx/maps/usecase/service/CompanySiteService.java b/backend/src/main/java/ch/xxx/maps/usecase/service/CompanySiteService.java index 7dce88a..467b445 100644 --- a/backend/src/main/java/ch/xxx/maps/usecase/service/CompanySiteService.java +++ b/backend/src/main/java/ch/xxx/maps/usecase/service/CompanySiteService.java @@ -68,35 +68,6 @@ public Collection findCompanySiteByTitleAndYear(String title, Long title = title.trim().toLowerCase(); List companySites = this.companySiteRepository.findByTitleFromTo(title, beginOfYear, endOfYear) .stream().peek(this.entityManager::detach).toList(); -// companySites = addEntities(withPolygons, withRings, withLocations, companySites); - return companySites; - } - - - - private List addEntities(boolean withPolygons, boolean withRings, boolean withLocations, - List companySites) { - if (withPolygons) { - Map> fetchPolygons = this.fetchPolygonEntitys(companySites); - Map> fetchRings = !withRings ? Map.of() - : this.fetchRings(fetchPolygons.values().stream().flatMap(List::stream).toList()); - Map> fetchLocations = !withLocations ? Map.of() - : this.fetchLocations(fetchRings.values().stream().flatMap(List::stream).toList()); - companySites.forEach(myCompanySite -> { - myCompanySite.setPolygons(new HashSet<>(fetchPolygons.getOrDefault(myCompanySite.getId(), List.of()))); - if (withRings) { - myCompanySite.getPolygons().forEach(myPolygon -> { - myPolygon.setRings(new HashSet<>(fetchRings.getOrDefault(myPolygon.getId(), List.of()))); - if (withLocations) { - myPolygon.getRings().forEach(myRing -> { - myRing.setLocations( - new HashSet<>(fetchLocations.getOrDefault(myRing.getId(), List.of()))); - }); - } - }); - } - }); - } return companySites; } @@ -108,7 +79,6 @@ public Optional findCompanySiteById(Long id) { public Optional findCompanySiteByIdDetached(Long id, boolean withPolygons, boolean withRings, boolean withLocations) { return Optional.ofNullable(id).flatMap(myId -> this.companySiteRepository.findById(myId)).stream() -// .peek(myCompanySite -> this.addEntities(withPolygons, withRings, withLocations, List.of(myCompanySite))) .findFirst(); } @@ -208,7 +178,7 @@ public LinkedHashMap> fetchLocationDtos(List ri .findAllByRingIds(ringDtos.stream().map(RingDto::getId).collect(Collectors.toList())).stream() .peek(this.entityManager::detach).toList(); return ringDtos.stream() - .map(myRi -> Map.entry(myRi, findLocations(locations, myRi.getId()))) + .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)); } @@ -236,6 +206,7 @@ public Map> fetchLocations(List rings) { private List findLocations(List locations, Long myRiId) { return locations.stream().filter(myLocation -> myLocation.getRing().getId().equals(myRiId)) + .sorted((a,b) -> a.getOrderId().compareTo(b.getOrderId())) .collect(Collectors.toList()); } }