diff --git a/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java b/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java index 3ce2b0bd2..b6be226a7 100644 --- a/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java +++ b/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java @@ -225,11 +225,10 @@ public ResponseEntity createNetworkCompositeModification(@RequestBody List @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) + .body(networkModificationService.getCompositeModificationContentMetadata(compositeModificationId) ); } 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 08877b28e..c0349135e 100644 --- a/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java +++ b/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java @@ -194,6 +194,7 @@ public List getModifications(UUID groupUuid, boolean onlyMeta return getModifications(groupUuid, onlyMetadata, errorOnGroupNotFound, false); } + // TODO : regarder cette récup de métadata plutôt que la mienne @Transactional(readOnly = true) public List getModifications(UUID groupUuid, boolean onlyMetadata, boolean errorOnGroupNotFound, boolean onlyStashed) { try { @@ -315,6 +316,15 @@ public ModificationInfos getModificationInfo(UUID modificationUuid) { return getModificationInfos(optionalModificationEntity.get()); } + @Transactional(readOnly = true) + public ModificationInfos getMetadata(UUID modificationUuid) { + Optional optionalModificationEntity = modificationRepository.findById(modificationUuid); + if (!optionalModificationEntity.isPresent()) { + throw new NetworkModificationException(MODIFICATION_NOT_FOUND, modificationUuid.toString()); + } + return ModificationInfos.fromEntity(optionalModificationEntity.get()); + } + @Transactional // To have the 2 delete in the same transaction (atomic) public void deleteModificationGroup(UUID groupUuid, boolean errorOnGroupNotFound) { try { @@ -388,16 +398,17 @@ public List getModificationsInfos(@NonNull List uuids) } /** + * @param onlyMetadata if true, only returns the basic data common to all the modificaions * @return the data from all the network modification contained in the composite modification sent as parameters */ @Transactional(readOnly = true) - public List getCompositeModificationsContentInfos(@NonNull List uuids) { + public List getCompositeModificationsContentInfos(@NonNull List uuids, boolean onlyMetadata) { List entities = new ArrayList<>(); uuids.forEach(uuid -> { List foundEntities = modificationRepository.findModificationIdsByCompositeModificationId(uuid); List orderedModifications = foundEntities .stream() - .map(this::getModificationInfo) + .map(onlyMetadata ? this::getMetadata : this::getModificationInfo) .toList(); entities.addAll(orderedModifications); } 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 aec3b347e..2e1e8c6ac 100644 --- a/src/main/java/org/gridsuite/modification/server/service/NetworkModificationService.java +++ b/src/main/java/org/gridsuite/modification/server/service/NetworkModificationService.java @@ -78,8 +78,8 @@ public List getNetworkModifications(UUID groupUuid, boolean o @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)); + public List getCompositeModificationContentMetadata(UUID compositeModificationUuid) { + return networkModificationRepository.getCompositeModificationsContentInfos(List.of(compositeModificationUuid), true); } @Transactional(readOnly = true) @@ -291,7 +291,7 @@ public Optional duplicateModifications(UUID targetGro public Optional insertCompositeModifications(UUID targetGroupUuid, UUID networkUuid, String variantId, ReportInfos reportInfos, List modificationsUuids) { - List modificationInfos = networkModificationRepository.getCompositeModificationsContentInfos(modificationsUuids); + List modificationInfos = networkModificationRepository.getCompositeModificationsContentInfos(modificationsUuids, false); networkModificationRepository.saveModificationInfos(targetGroupUuid, modificationInfos); return applyModifications(networkUuid, variantId, reportInfos, modificationInfos); } @@ -334,7 +334,7 @@ public Optional applyModificationsFromUuids(UUID netw String variantId, ReportInfos reportInfos, List modificationsUuids) { - List modificationInfos = networkModificationRepository.getCompositeModificationsContentInfos(modificationsUuids); + List modificationInfos = networkModificationRepository.getCompositeModificationsContentInfos(modificationsUuids, false); return applyModifications(networkUuid, variantId, reportInfos, modificationInfos); } }