diff --git a/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java b/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java index 8175e5f04..ca68aad31 100644 --- a/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java +++ b/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java @@ -220,6 +220,16 @@ public ResponseEntity createNetworkCompositeModification(@RequestBody List return ResponseEntity.ok().body(networkModificationService.createNetworkCompositeModification(modificationUuids)); } + @GetMapping(value = "/network-composite-modification/{uuid}/network-modifications", produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Get the list of the network modifications inside a composite modification") + @ApiResponse(responseCode = "200", description = "List of the modifications inside the composite modification") + public ResponseEntity> getNetworkModificationsFromComposite(@PathVariable("uuid") UUID compositeModificationUuid) { + return ResponseEntity.ok() + .contentType(MediaType.APPLICATION_JSON) + .body(networkModificationService.getNetworkModificationsFromComposite(compositeModificationUuid) + ); + } + @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/ModificationRepository.java b/src/main/java/org/gridsuite/modification/server/repositories/ModificationRepository.java index 1568bd632..bf9265ccd 100644 --- a/src/main/java/org/gridsuite/modification/server/repositories/ModificationRepository.java +++ b/src/main/java/org/gridsuite/modification/server/repositories/ModificationRepository.java @@ -37,6 +37,12 @@ public interface ModificationRepository extends JpaRepository findMetadataIn(List uuids); + /** + * @return base data of the network modifications (the data from the main common table, not those specific to each modification) + */ + @Query(value = "SELECT new ModificationEntity(m.id, m.type, m.date, m.stashed, m.activated, m.messageType, m.messageValues) FROM ModificationEntity m WHERE m.id IN (?1) order by m.modificationsOrder") + List findBaseDataByIdIn(List uuids); + @Query(value = "SELECT m FROM ModificationEntity m WHERE m.id IN (?1) ORDER BY m.modificationsOrder") List findAllByIdIn(List uuids); 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 1b56810e7..b2759fdab 100644 --- a/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java +++ b/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java @@ -394,6 +394,20 @@ public List getModificationsInfos(@NonNull List uuids) return uuids.stream().map(entities::get).filter(Objects::nonNull).map(this::getModificationInfos).toList(); } + /** + * returns the data from all the network modifications contained in the composite modification sent as parameter + * but only returns the basic data common to all the modifications form the ModificationInfos, not from the extended classes + */ + @Transactional(readOnly = true) + public List getBasicNetworkModificationsFromComposite(@NonNull UUID uuid) { + List networkModificationsUuids = modificationRepository.findModificationIdsByCompositeModificationId(uuid); + List networkModificationsEntities = modificationRepository.findBaseDataByIdIn(networkModificationsUuids); + return networkModificationsEntities + .stream() + .map(this::getModificationInfos) + .toList(); + } + @Transactional(readOnly = true) public List getCompositeModificationsInfos(@NonNull List uuids) { List entities = new ArrayList<>(); 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 6ca1b03e2..6470752a7 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,11 @@ public List getNetworkModifications(UUID groupUuid, boolean o return getNetworkModifications(groupUuid, onlyMetadata, errorOnGroupNotFound, false); } + @Transactional(readOnly = true) + public List getNetworkModificationsFromComposite(UUID compositeModificationUuid) { + return networkModificationRepository.getBasicNetworkModificationsFromComposite(compositeModificationUuid); + } + @Transactional(readOnly = true) public ModificationInfos getNetworkModification(UUID networkModificationUuid) { return networkModificationRepository.getModificationInfo(networkModificationUuid); diff --git a/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java b/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java index 5f0228702..712aa5b83 100644 --- a/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java +++ b/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java @@ -90,6 +90,7 @@ class ModificationControllerTest { private static final String URI_NETWORK_MODIF_BASE = "/v1/network-modifications"; private static final String URI_COMPOSITE_NETWORK_MODIF_BASE = "/v1/network-composite-modifications"; + private static final String URI_GET_COMPOSITE_NETWORK_MODIF_CONTENT = "/v1/network-composite-modification/"; private static final String URI_NETWORK_MODIF_PARAMS = "&groupUuid=" + TEST_GROUP_ID + "&reportUuid=" + TEST_REPORT_ID + "&reporterId=" + UUID.randomUUID(); private static final String URI_NETWORK_MODIF = URI_NETWORK_MODIF_BASE + "?networkUuid=" + TEST_NETWORK_ID + URI_NETWORK_MODIF_PARAMS; private static final String URI_NETWORK_MODIF_BUS_BREAKER = URI_NETWORK_MODIF_BASE + "?networkUuid=" + TEST_NETWORK_BUS_BREAKER_ID + URI_NETWORK_MODIF_PARAMS; @@ -695,9 +696,10 @@ void testMoveModificationInSameGroup() throws Exception { @Test void testNetworkCompositeModification() throws Exception { - // Insert a switch modification in the group - List modificationList = createSomeSwitchModifications(TEST_GROUP_ID, 1); - assertEquals(1, modificationRepository.getModifications(TEST_GROUP_ID, true, true).size()); + // Insert some switch modifications in the group + int modificationsNumber = 2; + List modificationList = createSomeSwitchModifications(TEST_GROUP_ID, modificationsNumber); + assertEquals(modificationsNumber, modificationRepository.getModifications(TEST_GROUP_ID, true, true).size()); // Create a composite modification with the switch modification List modificationUuids = modificationList.stream().map(ModificationInfos::getUuid).toList(); @@ -710,7 +712,13 @@ void testNetworkCompositeModification() throws Exception { .build(); UUID compositeModificationUuid = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { }); assertThat(modificationRepository.getModificationInfo(compositeModificationUuid)).recursivelyEquals(compositeModificationInfos); - assertEquals(1, modificationRepository.getModifications(TEST_GROUP_ID, true, true).size()); + assertEquals(modificationsNumber, modificationRepository.getModifications(TEST_GROUP_ID, true, true).size()); + + // get the composite modification metadata + mvcResult = mockMvc.perform(get(URI_GET_COMPOSITE_NETWORK_MODIF_CONTENT + compositeModificationUuid + "/network-modifications")) + .andExpect(status().isOk()).andReturn(); + List compositeModificationContent = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { }); + assertEquals(modificationsNumber, compositeModificationContent.size()); // Insert the composite modification in the group mvcResult = mockMvc.perform( @@ -725,10 +733,10 @@ void testNetworkCompositeModification() throws Exception { assertApplicationStatusOK(mvcResult); List newModificationList = modificationRepository.getModifications(TEST_GROUP_ID, false, true); - assertEquals(2, newModificationList.size()); + assertEquals(modificationsNumber * 2, newModificationList.size()); List newModificationUuidList = newModificationList.stream().map(ModificationInfos::getUuid).toList(); assertEquals(modificationUuids.get(0), newModificationUuidList.get(0)); - assertThat(modificationList.get(0)).recursivelyEquals(newModificationList.get(1)); + assertThat(modificationList.get(0)).recursivelyEquals(newModificationList.get(modificationsNumber)); } @Test