From 190e807d013cfa6e1074c204891e5b4c22664ce1 Mon Sep 17 00:00:00 2001 From: Mathieu DEHARBE Date: Tue, 8 Oct 2024 14:42:20 +0200 Subject: [PATCH] draft getCompositeModification endpoint Signed-off-by: Mathieu DEHARBE --- .../server/NetworkModificationController.java | 13 +++++++++++++ .../repositories/NetworkModificationRepository.java | 5 ++++- .../server/service/NetworkModificationService.java | 10 ++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java b/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java index b8e6bddce..3ce2b0bd2 100644 --- a/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java +++ b/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java @@ -220,6 +220,19 @@ public ResponseEntity createNetworkCompositeModification(@RequestBody List return ResponseEntity.ok().body(networkModificationService.createNetworkCompositeModification(modificationUuids)); } + @GetMapping(value = "/network-composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Get the content of a composite modification via its id") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Content of the composite modification"), + @ApiResponse(responseCode = "404", description = "This composite modification does not exist")} + ) + // TODO : renvoyer plutôt des métadonnées plutôt que des modifications complètes ?? (List) ?? => bof pas de name dedans ! + public ResponseEntity> getCompositeModificationContent(@PathVariable("id") UUID compositeModificationId) { + return ResponseEntity.ok() + .contentType(MediaType.APPLICATION_JSON) + .body(networkModificationService.getCompositeModificationContentInfos(compositeModificationId) + ); + } + @PostMapping(value = "/network-modifications", consumes = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Duplicate some modifications without group ownership") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The duplicated modifications uuids mapped with their source uuid")}) diff --git a/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java b/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java index 8c156b2cb..08877b28e 100644 --- a/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java +++ b/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java @@ -387,8 +387,11 @@ public List getModificationsInfos(@NonNull List uuids) return uuids.stream().map(entities::get).filter(Objects::nonNull).map(this::getModificationInfos).toList(); } + /** + * @return the data from all the network modification contained in the composite modification sent as parameters + */ @Transactional(readOnly = true) - public List getCompositeModificationsInfos(@NonNull List uuids) { + public List getCompositeModificationsContentInfos(@NonNull List uuids) { List entities = new ArrayList<>(); uuids.forEach(uuid -> { List foundEntities = modificationRepository.findModificationIdsByCompositeModificationId(uuid); diff --git a/src/main/java/org/gridsuite/modification/server/service/NetworkModificationService.java b/src/main/java/org/gridsuite/modification/server/service/NetworkModificationService.java index b3d21d658..aec3b347e 100644 --- a/src/main/java/org/gridsuite/modification/server/service/NetworkModificationService.java +++ b/src/main/java/org/gridsuite/modification/server/service/NetworkModificationService.java @@ -76,6 +76,12 @@ public List getNetworkModifications(UUID groupUuid, boolean o return getNetworkModifications(groupUuid, onlyMetadata, errorOnGroupNotFound, false); } + @Transactional(readOnly = true) + // Need a transaction for collections lazy loading ==> TODO : this is copy pasted, is this true here ? + public List getCompositeModificationContentInfos(UUID compositeModificationUuid) { + return networkModificationRepository.getCompositeModificationsContentInfos(List.of(compositeModificationUuid)); + } + @Transactional(readOnly = true) public ModificationInfos getNetworkModification(UUID networkModificationUuid) { return networkModificationRepository.getModificationInfo(networkModificationUuid); @@ -285,7 +291,7 @@ public Optional duplicateModifications(UUID targetGro public Optional insertCompositeModifications(UUID targetGroupUuid, UUID networkUuid, String variantId, ReportInfos reportInfos, List modificationsUuids) { - List modificationInfos = networkModificationRepository.getCompositeModificationsInfos(modificationsUuids); + List modificationInfos = networkModificationRepository.getCompositeModificationsContentInfos(modificationsUuids); networkModificationRepository.saveModificationInfos(targetGroupUuid, modificationInfos); return applyModifications(networkUuid, variantId, reportInfos, modificationInfos); } @@ -328,7 +334,7 @@ public Optional applyModificationsFromUuids(UUID netw String variantId, ReportInfos reportInfos, List modificationsUuids) { - List modificationInfos = networkModificationRepository.getCompositeModificationsInfos(modificationsUuids); + List modificationInfos = networkModificationRepository.getCompositeModificationsContentInfos(modificationsUuids); return applyModifications(networkUuid, variantId, reportInfos, modificationInfos); } }