From bd3f5c0e1a4994027f338009851c0a1cdfe2ee47 Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Mon, 16 Dec 2024 15:54:57 +0100 Subject: [PATCH 01/17] feat: migrate modifications endpoints to root network uuid usage Signed-off-by: LE SAULNIER Kevin --- .../study/server/StudyController.java | 49 ++-- .../rootnetwork/RootNetworkRepository.java | 2 +- .../service/NetworkModificationService.java | 7 +- .../service/RootNetworkNodeInfoService.java | 9 +- .../server/service/RootNetworkService.java | 2 +- .../study/server/service/StudyService.java | 73 ++--- .../study/server/NetworkModificationTest.java | 273 ++++++++++-------- .../server/NetworkModificationTreeTest.java | 9 +- .../server/NetworkModificationUnitTest.java | 3 +- .../org/gridsuite/study/server/StudyTest.java | 43 +-- 10 files changed, 264 insertions(+), 206 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/StudyController.java b/src/main/java/org/gridsuite/study/server/StudyController.java index 56bdc90ba..d3b4940cf 100644 --- a/src/main/java/org/gridsuite/study/server/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/StudyController.java @@ -558,9 +558,9 @@ public ResponseEntity moveModification(@PathVariable("studyUuid") UUID stu @PathVariable("nodeUuid") UUID nodeUuid, @PathVariable("modificationUuid") UUID modificationUuid, @Nullable @Parameter(description = "move before, if no value move to end") @RequestParam(value = "beforeUuid") UUID beforeUuid, + @Parameter(description = "active root network uuid - will apply iteratively modifications for this root network only") @RequestParam(value = "rootNetworkUuid") UUID rootNetworkUuid, @RequestHeader(HEADER_USER_ID) String userId) { - UUID rootNetworkUuid = studyService.getStudyFirstRootNetworkUuid(studyUuid); - studyService.assertCanModifyNode(studyUuid, nodeUuid, rootNetworkUuid); + studyService.assertCanUpdateModifications(studyUuid, nodeUuid); studyService.moveModifications(studyUuid, nodeUuid, nodeUuid, rootNetworkUuid, List.of(modificationUuid), beforeUuid, userId); return ResponseEntity.ok().build(); } @@ -572,14 +572,15 @@ public ResponseEntity moveOrCopyModifications(@PathVariable("studyUuid") U @PathVariable("nodeUuid") UUID nodeUuid, @RequestParam("action") StudyConstants.ModificationsActionType action, @Nullable @RequestParam("originNodeUuid") UUID originNodeUuid, + @Parameter(description = "active root network uuid - will apply iteratively modifications for this root network only") @RequestParam(value = "rootNetworkUuid") UUID rootNetworkUuid, @RequestBody List modificationsToCopyUuidList, @RequestHeader(HEADER_USER_ID) String userId) { studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid); - UUID rootNetworkUuid = studyService.getStudyFirstRootNetworkUuid(studyUuid); - studyService.assertCanModifyNode(studyUuid, nodeUuid, rootNetworkUuid); + rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkUuid); + studyService.assertCanUpdateModifications(studyUuid, nodeUuid); if (originNodeUuid != null) { studyService.assertIsNodeExist(studyUuid, originNodeUuid); - studyService.assertCanModifyNode(studyUuid, originNodeUuid, rootNetworkUuid); + studyService.assertCanUpdateModifications(studyUuid, originNodeUuid); } switch (action) { case COPY, INSERT: @@ -1131,10 +1132,10 @@ public ResponseEntity getNetworkModifications(@Parameter(description = " @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The network modification was created"), @ApiResponse(responseCode = "404", description = "The study/node is not found")}) public ResponseEntity createNetworkModification(@Parameter(description = "Study UUID") @PathVariable("studyUuid") UUID studyUuid, @Parameter(description = "Node UUID") @PathVariable("nodeUuid") UUID nodeUuid, + @Parameter(description = "Active root network uuid - will apply iteratively modifications for this root network only") @RequestParam(value = "rootNetworkUuid") UUID rootNetworkUuid, @RequestBody String modificationAttributes, @RequestHeader(HEADER_USER_ID) String userId) { - UUID rootNetworkUuid = studyService.getStudyFirstRootNetworkUuid(studyUuid); - studyService.assertCanModifyNode(studyUuid, nodeUuid, rootNetworkUuid); + studyService.assertCanUpdateModifications(studyUuid, nodeUuid); studyService.createNetworkModification(studyUuid, modificationAttributes, nodeUuid, rootNetworkUuid, userId); return ResponseEntity.ok().build(); } @@ -1147,9 +1148,8 @@ public ResponseEntity updateNetworkModification(@Parameter(description = " @Parameter(description = "Network modification UUID") @PathVariable("uuid") UUID networkModificationUuid, @RequestBody String modificationAttributes, @RequestHeader(HEADER_USER_ID) String userId) { - UUID rootNetworkUuid = studyService.getStudyFirstRootNetworkUuid(studyUuid); - studyService.assertCanModifyNode(studyUuid, nodeUuid, rootNetworkUuid); - studyService.updateNetworkModification(studyUuid, modificationAttributes, nodeUuid, rootNetworkUuid, networkModificationUuid, userId); + studyService.assertCanUpdateModifications(studyUuid, nodeUuid); + studyService.updateNetworkModification(studyUuid, modificationAttributes, nodeUuid, networkModificationUuid, userId); return ResponseEntity.ok().build(); } @@ -1160,9 +1160,8 @@ public ResponseEntity deleteNetworkModifications(@Parameter(description = @Parameter(description = "Node UUID") @PathVariable("nodeUuid") UUID nodeUuid, @Parameter(description = "Network modification UUIDs") @RequestParam(name = "uuids", required = false) List networkModificationUuids, @RequestHeader(HEADER_USER_ID) String userId) { - UUID rootNetworkUuid = studyService.getStudyFirstRootNetworkUuid(studyUuid); - studyService.assertCanModifyNode(studyUuid, nodeUuid, rootNetworkUuid); - studyService.deleteNetworkModifications(studyUuid, nodeUuid, rootNetworkUuid, networkModificationUuids, userId); + studyService.assertCanUpdateModifications(studyUuid, nodeUuid); + studyService.deleteNetworkModifications(studyUuid, nodeUuid, networkModificationUuids, userId); return ResponseEntity.ok().build(); } @@ -1173,10 +1172,10 @@ public ResponseEntity deleteNetworkModifications(@Parameter(description = public ResponseEntity stashNetworkModifications(@Parameter(description = "Study UUID") @PathVariable("studyUuid") UUID studyUuid, @Parameter(description = "Node UUID") @PathVariable("nodeUuid") UUID nodeUuid, @Parameter(description = "Network modification UUIDs") @RequestParam("uuids") List networkModificationUuids, + @Parameter(description = "active root network uuid - will apply iteratively modifications for this root network only") @RequestParam(value = "rootNetworkUuid") UUID rootNetworkUuid, @Parameter(description = "Stashed Modification") @RequestParam(name = "stashed", required = true) Boolean stashed, @RequestHeader(HEADER_USER_ID) String userId) { - UUID rootNetworkUuid = studyService.getStudyFirstRootNetworkUuid(studyUuid); - studyService.assertCanModifyNode(studyUuid, nodeUuid, rootNetworkUuid); + studyService.assertCanUpdateModifications(studyUuid, nodeUuid); if (stashed.booleanValue()) { studyService.stashNetworkModifications(studyUuid, nodeUuid, rootNetworkUuid, networkModificationUuids, userId); } else { @@ -1191,10 +1190,10 @@ public ResponseEntity stashNetworkModifications(@Parameter(description = " public ResponseEntity updateNetworkModificationsActivation(@Parameter(description = "Study UUID") @PathVariable("studyUuid") UUID studyUuid, @Parameter(description = "Node UUID") @PathVariable("nodeUuid") UUID nodeUuid, @Parameter(description = "Network modification UUIDs") @RequestParam("uuids") List networkModificationUuids, + @Parameter(description = "active root network uuid - will apply iteratively modifications for this root network only") @RequestParam(value = "rootNetworkUuid") UUID rootNetworkUuid, @Parameter(description = "New activated value") @RequestParam(name = "activated", required = true) Boolean activated, @RequestHeader(HEADER_USER_ID) String userId) { - UUID rootNetworkUuid = studyService.getStudyFirstRootNetworkUuid(studyUuid); - studyService.assertCanModifyNode(studyUuid, nodeUuid, rootNetworkUuid); + studyService.assertCanUpdateModifications(studyUuid, nodeUuid); studyService.updateNetworkModificationsActivation(studyUuid, nodeUuid, rootNetworkUuid, networkModificationUuids, userId, activated); return ResponseEntity.ok().build(); } @@ -1247,8 +1246,7 @@ public ResponseEntity deleteNode(@Parameter(description = "study uuid") @P @Parameter(description = "ids of children to remove") @RequestParam("ids") List nodeIds, @Parameter(description = "deleteChildren") @RequestParam(value = "deleteChildren", defaultValue = "false") boolean deleteChildren, @RequestHeader(HEADER_USER_ID) String userId) { - UUID rootNetworkUuid = studyService.getStudyFirstRootNetworkUuid(studyUuid); - studyService.deleteNodes(studyUuid, nodeIds, rootNetworkUuid, deleteChildren, userId); + studyService.deleteNodes(studyUuid, nodeIds, deleteChildren, userId); return ResponseEntity.ok().build(); } @@ -1365,7 +1363,7 @@ public ResponseEntity buildNode(@Parameter(description = "Study uuid") @Pa @Parameter(description = "rootNetworkUuid") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid, @Parameter(description = "nodeUuid") @PathVariable("nodeUuid") UUID nodeUuid, @RequestHeader(HEADER_USER_ID) String userId) { - studyService.assertNoBuildNoComputation(studyUuid, nodeUuid, rootNetworkUuid); + studyService.assertNoBuildNoComputationForRootNetworkNode(nodeUuid, rootNetworkUuid); studyService.buildNode(studyUuid, nodeUuid, rootNetworkUuid, userId); return ResponseEntity.ok().build(); } @@ -1607,8 +1605,7 @@ public ResponseEntity createDynamicSimulationEvent(@Parameter(description @Parameter(description = "Node UUID") @PathVariable("nodeUuid") UUID nodeUuid, @RequestBody EventInfos event, @RequestHeader(HEADER_USER_ID) String userId) { - UUID rootNetworkUuid = studyService.getStudyFirstRootNetworkUuid(studyUuid); - studyService.assertCanModifyNode(studyUuid, nodeUuid, rootNetworkUuid); + studyService.assertCanUpdateModifications(studyUuid, nodeUuid); studyService.createDynamicSimulationEvent(studyUuid, nodeUuid, userId, event); return ResponseEntity.ok().build(); } @@ -1622,8 +1619,7 @@ public ResponseEntity updateDynamicSimulationEvent(@Parameter(description @Parameter(description = "Node UUID") @PathVariable("nodeUuid") UUID nodeUuid, @RequestBody EventInfos event, @RequestHeader(HEADER_USER_ID) String userId) { - UUID rootNetworkUuid = studyService.getStudyFirstRootNetworkUuid(studyUuid); - studyService.assertCanModifyNode(studyUuid, nodeUuid, rootNetworkUuid); + studyService.assertCanUpdateModifications(studyUuid, nodeUuid); studyService.updateDynamicSimulationEvent(studyUuid, nodeUuid, userId, event); return ResponseEntity.ok().build(); } @@ -1637,8 +1633,7 @@ public ResponseEntity deleteDynamicSimulationEvents(@Parameter(description @Parameter(description = "Node UUID") @PathVariable("nodeUuid") UUID nodeUuid, @Parameter(description = "Dynamic simulation event UUIDs") @RequestParam("eventUuids") List eventUuids, @RequestHeader(HEADER_USER_ID) String userId) { - UUID rootNetworkUuid = studyService.getStudyFirstRootNetworkUuid(studyUuid); - studyService.assertCanModifyNode(studyUuid, nodeUuid, rootNetworkUuid); + studyService.assertCanUpdateModifications(studyUuid, nodeUuid); studyService.deleteDynamicSimulationEvents(studyUuid, nodeUuid, userId, eventUuids); return ResponseEntity.ok().build(); } @@ -1748,7 +1743,7 @@ public ResponseEntity copyVoltageInitModifications(@PathVariable("studyUui @PathVariable("nodeUuid") UUID nodeUuid, @RequestHeader(HEADER_USER_ID) String userId) { studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid); - studyService.assertCanModifyNode(studyUuid, nodeUuid, rootNetworkUuid); + studyService.assertCanUpdateModifications(studyUuid, nodeUuid); studyService.copyVoltageInitModifications(studyUuid, nodeUuid, rootNetworkUuid, userId); return ResponseEntity.ok().build(); } diff --git a/src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkRepository.java b/src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkRepository.java index 2977288d7..64e50ddb1 100644 --- a/src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkRepository.java +++ b/src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkRepository.java @@ -30,5 +30,5 @@ public interface RootNetworkRepository extends JpaRepository findWithRootNetworkNodeInfosById(UUID rootNetworkUuid); - boolean existsByIdAndStudyId(UUID studyUuid, UUID id); + boolean existsByIdAndStudyId(UUID rootNetworkUuid, UUID studyUuid); } diff --git a/src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java b/src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java index 98872e0ec..eea9c7c52 100644 --- a/src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java +++ b/src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java @@ -318,11 +318,14 @@ public Optional moveModifications(UUID originGroupUui var path = UriComponentsBuilder.fromPath(GROUP_PATH) .queryParam(QUERY_PARAM_ACTION, ModificationsActionType.MOVE.name()) .queryParam(NETWORK_UUID, networkUuid) - .queryParam(REPORT_UUID, rootNetworkNodeInfoEntity.getModificationReports().get(networkModificationNodeInfoEntity.getId())) .queryParam(REPORTER_ID, networkModificationNodeInfoEntity.getId()) - .queryParam(VARIANT_ID, rootNetworkNodeInfoEntity.getVariantId()) .queryParam("originGroupUuid", originGroupUuid) .queryParam("build", buildTargetNode); + + if (rootNetworkNodeInfoEntity != null) { + path.queryParam(VARIANT_ID, rootNetworkNodeInfoEntity.getVariantId()) + .queryParam(REPORT_UUID, rootNetworkNodeInfoEntity.getModificationReports().get(networkModificationNodeInfoEntity.getId())); + } if (beforeUuid != null) { path.queryParam("before", beforeUuid); } diff --git a/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java b/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java index 75b502c19..6546a6ec1 100644 --- a/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java +++ b/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java @@ -315,12 +315,19 @@ public List getComputationResultUuids(UUID studyUuid, ComputationType comp .toList(); } - public void assertNoRootNetworkModificationInfoIsBuilding(UUID studyUuid) { + public void assertNoRootNetworkNodeIsBuilding(UUID studyUuid) { if (rootNetworkNodeInfoRepository.existsByStudyUuidAndBuildStatus(studyUuid, BuildStatus.BUILDING)) { throw new StudyException(NOT_ALLOWED, "No modification is allowed during a node building."); } } + public void assertNetworkNodeIsNotBuilding(UUID rootNetworkUuid, UUID nodeUuid) { + NodeBuildStatusEmbeddable buildStatusEmbeddable = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(nodeUuid, rootNetworkUuid).map(RootNetworkNodeInfoEntity::getNodeBuildStatus).orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); + if (buildStatusEmbeddable.getGlobalBuildStatus().isBuilding() || buildStatusEmbeddable.getLocalBuildStatus().isBuilding()) { + throw new StudyException(NOT_ALLOWED, "No modification is allowed during a node building."); + } + } + private void addLink(NetworkModificationNodeInfoEntity nodeInfoEntity, RootNetworkEntity rootNetworkEntity, RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity) { nodeInfoEntity.addRootNetworkNodeInfo(rootNetworkNodeInfoEntity); rootNetworkEntity.addRootNetworkNodeInfo(rootNetworkNodeInfoEntity); diff --git a/src/main/java/org/gridsuite/study/server/service/RootNetworkService.java b/src/main/java/org/gridsuite/study/server/service/RootNetworkService.java index 7d20889d4..53454671a 100644 --- a/src/main/java/org/gridsuite/study/server/service/RootNetworkService.java +++ b/src/main/java/org/gridsuite/study/server/service/RootNetworkService.java @@ -156,7 +156,7 @@ public RootNetworkCreationRequestEntity insertCreationRequest(UUID rootNetworkIn return rootNetworkCreationRequestRepository.save(RootNetworkCreationRequestEntity.builder().id(rootNetworkInCreationUuid).studyUuid(studyEntity.getId()).userId(userId).build()); } - public void assertIsRootNetworkInStudy(UUID rootNetworkUuid, UUID studyUuid) { + public void assertIsRootNetworkInStudy(UUID studyUuid, UUID rootNetworkUuid) { if (!rootNetworkRepository.existsByIdAndStudyId(rootNetworkUuid, studyUuid)) { throw new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND); } diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index de2bc9a05..16dd9f35f 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -281,7 +281,7 @@ public BasicStudyInfos createStudy(UUID caseUuid, String userId, UUID studyUuid, @Transactional public void deleteRootNetwork(UUID studyUuid, UUID rootNetworkUuid, String userId) { assertIsStudyExist(studyUuid); - rootNetworkService.assertIsRootNetworkInStudy(rootNetworkUuid, studyUuid); + rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkUuid); rootNetworkService.delete(rootNetworkUuid); } @@ -739,10 +739,9 @@ public void assertIsStudyExist(UUID studyUuid) { } @Transactional - // TODO Need to deal with all root networks - public void assertCanModifyNode(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid) { + public void assertCanUpdateModifications(UUID studyUuid, UUID nodeUuid) { assertIsNodeNotReadOnly(nodeUuid); - assertNoBuildNoComputation(studyUuid, nodeUuid, rootNetworkUuid); + assertNoBuildNoComputationForNode(studyUuid, nodeUuid); } public void assertIsStudyAndNodeExist(UUID studyUuid, UUID nodeUuid) { @@ -750,9 +749,16 @@ public void assertIsStudyAndNodeExist(UUID studyUuid, UUID nodeUuid) { assertIsNodeExist(studyUuid, nodeUuid); } - public void assertNoBuildNoComputation(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid) { + public void assertNoBuildNoComputationForRootNetworkNode(UUID nodeUuid, UUID rootNetworkUuid) { rootNetworkNodeInfoService.assertComputationNotRunning(nodeUuid, rootNetworkUuid); - rootNetworkNodeInfoService.assertNoRootNetworkModificationInfoIsBuilding(studyUuid); + rootNetworkNodeInfoService.assertNetworkNodeIsNotBuilding(rootNetworkUuid, nodeUuid); + } + + public void assertNoBuildNoComputationForNode(UUID studyUuid, UUID nodeUuid) { + rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetwork -> { + rootNetworkNodeInfoService.assertComputationNotRunning(nodeUuid, rootNetwork.getId()); + }); + rootNetworkNodeInfoService.assertNoRootNetworkNodeIsBuilding(studyUuid); } public void assertRootNodeOrBuiltNode(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid) { @@ -1200,12 +1206,12 @@ public void createNetworkModification(UUID studyUuid, String createModificationA notificationService.emitElementUpdated(studyUuid, userId); } - public void updateNetworkModification(UUID studyUuid, String updateModificationAttributes, UUID nodeUuid, UUID rootNetworkUuid, UUID modificationUuid, String userId) { + public void updateNetworkModification(UUID studyUuid, String updateModificationAttributes, UUID nodeUuid, UUID modificationUuid, String userId) { List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); notificationService.emitStartModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.MODIFICATIONS_UPDATING_IN_PROGRESS); try { networkModificationService.updateModification(updateModificationAttributes, modificationUuid); - updateStatuses(studyUuid, nodeUuid, rootNetworkUuid, false); + updateStatuses(studyUuid, nodeUuid, false); } finally { notificationService.emitEndModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids); } @@ -1281,7 +1287,7 @@ public void duplicateStudyNode(UUID sourceStudyUuid, UUID targetStudyUuid, UUID checkStudyContainsNode(targetStudyUuid, referenceNodeUuid); UUID duplicatedNodeUuid = networkModificationTreeService.duplicateStudyNode(nodeToCopyUuid, referenceNodeUuid, insertMode); boolean invalidateBuild = networkModificationTreeService.hasModifications(nodeToCopyUuid, false); - updateStatuses(targetStudyUuid, duplicatedNodeUuid, self.getStudyFirstRootNetworkUuid(targetStudyUuid), true, invalidateBuild, true); + updateStatuses(targetStudyUuid, duplicatedNodeUuid, true, invalidateBuild, true); notificationService.emitElementUpdated(targetStudyUuid, userId); } @@ -1301,8 +1307,8 @@ public void moveStudyNode(UUID studyUuid, UUID nodeToMoveUuid, UUID rootNetworkU //Invalidating moved node or new children if necessary if (shouldInvalidateChildren) { - updateStatuses(studyUuid, nodeToMoveUuid, rootNetworkUuid, false, true, true); - oldChildren.forEach(child -> updateStatuses(studyUuid, child.getIdNode(), rootNetworkUuid, false, true, true)); + updateStatuses(studyUuid, nodeToMoveUuid, false, true, true); + oldChildren.forEach(child -> updateStatuses(studyUuid, child.getIdNode(), false, true, true)); } else { invalidateBuild(studyUuid, nodeToMoveUuid, rootNetworkUuid, false, true, true); } @@ -1333,11 +1339,11 @@ public void moveStudySubtree(UUID studyUuid, UUID parentNodeToMoveUuid, UUID roo networkModificationTreeService.moveStudySubtree(parentNodeToMoveUuid, referenceNodeUuid); if (networkModificationTreeService.getNodeBuildStatus(parentNodeToMoveUuid, rootNetworkUuid).isBuilt()) { - updateStatuses(studyUuid, parentNodeToMoveUuid, rootNetworkUuid, false, true, true); + updateStatuses(studyUuid, parentNodeToMoveUuid, false, true, true); } allChildren.stream() .filter(childUuid -> networkModificationTreeService.getNodeBuildStatus(childUuid, rootNetworkUuid).isBuilt()) - .forEach(childUuid -> updateStatuses(studyUuid, childUuid, rootNetworkUuid, false, true, true)); + .forEach(childUuid -> updateStatuses(studyUuid, childUuid, false, true, true)); notificationService.emitSubtreeMoved(studyUuid, parentNodeToMoveUuid, referenceNodeUuid); notificationService.emitElementUpdated(studyUuid, userId); @@ -1384,26 +1390,27 @@ public void invalidateBuild(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, } } - // TODO Need to deal with all root networks - private void updateStatuses(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid) { - updateStatuses(studyUuid, nodeUuid, rootNetworkUuid, true); + private void updateStatuses(UUID studyUuid, UUID nodeUuid) { + updateStatuses(studyUuid, nodeUuid, true); } - // TODO Need to deal with all root networks - private void updateStatuses(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, boolean invalidateOnlyChildrenBuildStatus) { - updateStatuses(studyUuid, nodeUuid, rootNetworkUuid, invalidateOnlyChildrenBuildStatus, true, true); + private void updateStatuses(UUID studyUuid, UUID nodeUuid, boolean invalidateOnlyChildrenBuildStatus) { + updateStatuses(studyUuid, nodeUuid, invalidateOnlyChildrenBuildStatus, true, true); } // TODO Need to deal with all root networks - private void updateStatuses(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, boolean invalidateOnlyChildrenBuildStatus, boolean invalidateBuild, boolean deleteVoltageInitResults) { + private void updateStatuses(UUID studyUuid, UUID nodeUuid, boolean invalidateOnlyChildrenBuildStatus, boolean invalidateBuild, boolean deleteVoltageInitResults) { if (invalidateBuild) { - invalidateBuild(studyUuid, nodeUuid, rootNetworkUuid, invalidateOnlyChildrenBuildStatus, false, deleteVoltageInitResults); + //TODO: to implement better, this is not really optimized + rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> { + invalidateBuild(studyUuid, nodeUuid, rootNetworkEntity.getId(), invalidateOnlyChildrenBuildStatus, false, deleteVoltageInitResults); + }); } emitAllComputationStatusChanged(studyUuid, nodeUuid); } @Transactional - public void deleteNetworkModifications(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, List modificationsUuids, String userId) { + public void deleteNetworkModifications(UUID studyUuid, UUID nodeUuid, List modificationsUuids, String userId) { List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); notificationService.emitStartModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.MODIFICATIONS_DELETING_IN_PROGRESS); try { @@ -1413,7 +1420,7 @@ public void deleteNetworkModifications(UUID studyUuid, UUID nodeUuid, UUID rootN UUID groupId = networkModificationTreeService.getModificationGroupUuid(nodeUuid); networkModificationService.deleteModifications(groupId, modificationsUuids); - updateStatuses(studyUuid, nodeUuid, rootNetworkUuid, false, false, false); + updateStatuses(studyUuid, nodeUuid, false, false, false); } finally { notificationService.emitEndDeletionEquipmentNotification(studyUuid, nodeUuid, childrenUuids); } @@ -1430,7 +1437,7 @@ public void stashNetworkModifications(UUID studyUuid, UUID nodeUuid, UUID rootNe } UUID groupId = networkModificationTreeService.getModificationGroupUuid(nodeUuid); networkModificationService.stashModifications(groupId, modificationsUuids); - updateStatuses(studyUuid, nodeUuid, rootNetworkUuid, false); + updateStatuses(studyUuid, nodeUuid, false); } finally { notificationService.emitEndModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids); } @@ -1447,7 +1454,7 @@ public void updateNetworkModificationsActivation(UUID studyUuid, UUID nodeUuid, } UUID groupId = networkModificationTreeService.getModificationGroupUuid(nodeUuid); networkModificationService.updateModificationsActivation(groupId, modificationsUuids, activated); - updateStatuses(studyUuid, nodeUuid, rootNetworkUuid, false); + updateStatuses(studyUuid, nodeUuid, false); } finally { notificationService.emitEndModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids); } @@ -1464,7 +1471,7 @@ public void restoreNetworkModifications(UUID studyUuid, UUID nodeUuid, UUID root } UUID groupId = networkModificationTreeService.getModificationGroupUuid(nodeUuid); networkModificationService.restoreModifications(groupId, modificationsUuids); - updateStatuses(studyUuid, nodeUuid, rootNetworkUuid, false); + updateStatuses(studyUuid, nodeUuid, false); } finally { notificationService.emitEndModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids); } @@ -1472,7 +1479,7 @@ public void restoreNetworkModifications(UUID studyUuid, UUID nodeUuid, UUID root } @Transactional - public void deleteNodes(UUID studyUuid, List nodeIds, UUID rootNetworkUuid, boolean deleteChildren, String userId) { + public void deleteNodes(UUID studyUuid, List nodeIds, boolean deleteChildren, String userId) { DeleteNodeInfos deleteNodeInfos = new DeleteNodeInfos(); for (UUID nodeId : nodeIds) { @@ -1516,7 +1523,7 @@ public void deleteNodes(UUID studyUuid, List nodeIds, UUID rootNetworkUuid } if (invalidateChildrenBuild) { - childrenNodes.forEach(nodeEntity -> updateStatuses(studyUuid, nodeEntity.getIdNode(), rootNetworkUuid, false, true, true)); + childrenNodes.forEach(nodeEntity -> updateStatuses(studyUuid, nodeEntity.getIdNode(), false, true, true)); } } @@ -1611,12 +1618,12 @@ public void moveModifications(UUID studyUuid, UUID targetNodeUuid, UUID originNo if (!targetNodeBelongsToSourceNodeSubTree) { // invalidate the whole subtree except maybe the target node itself (depends if we have built this node during the move) networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, targetNodeUuid, rootNetworkUuid, modificationResult)); - updateStatuses(studyUuid, targetNodeUuid, rootNetworkUuid, buildTargetNode, true, true); + updateStatuses(studyUuid, targetNodeUuid, buildTargetNode, true, true); } if (moveBetweenNodes) { // invalidate the whole subtree including the source node networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, originNodeUuid, rootNetworkUuid, modificationResult)); - updateStatuses(studyUuid, originNodeUuid, rootNetworkUuid, false, true, true); + updateStatuses(studyUuid, originNodeUuid, false, true, true); } } finally { notificationService.emitEndModificationEquipmentNotification(studyUuid, targetNodeUuid, childrenUuids); @@ -1639,7 +1646,7 @@ public void createModifications(UUID studyUuid, UUID nodeUuid, UUID rootNetworkU Optional networkModificationResult = networkModificationService.createModifications(modificationUuidList, networkUuid, networkModificationNodeInfoEntity, rootNetworkNodeInfoEntity, action); // invalidate the whole subtree except the target node (we have built this node during the duplication) networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, nodeUuid, rootNetworkUuid, modificationResult)); - updateStatuses(studyUuid, nodeUuid, rootNetworkUuid, true, true, true); + updateStatuses(studyUuid, nodeUuid, true, true, true); } finally { notificationService.emitEndModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids); } @@ -1726,7 +1733,7 @@ private List nodesTree(UUID nodeUuid) { private void updateNode(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, Optional networkModificationResult) { networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, nodeUuid, rootNetworkUuid, modificationResult)); - updateStatuses(studyUuid, nodeUuid, rootNetworkUuid); + updateStatuses(studyUuid, nodeUuid); } private void emitNetworkModificationImpacts(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, NetworkModificationResult networkModificationResult) { @@ -2023,7 +2030,7 @@ public void copyVoltageInitModifications(UUID studyUuid, UUID nodeUuid, UUID roo // invalidate the whole subtree except the target node (we have built this node during the duplication) networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, nodeUuid, rootNetworkUuid, modificationResult)); notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_VOLTAGE_INIT_RESULT); // send notification voltage init result has changed - updateStatuses(studyUuid, nodeUuid, rootNetworkUuid, true, true, false); // do not delete the voltage init results + updateStatuses(studyUuid, nodeUuid, true, true, false); // do not delete the voltage init results } finally { notificationService.emitEndModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids); } diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java index 486d4fe34..b327401a8 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java @@ -145,6 +145,7 @@ class NetworkModificationTest { private static final long TIMEOUT = 1000; private static final String URI_NETWORK_MODIF = "/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications"; + private static final String URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID = "/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications?rootNetworkUuid={rootNetworkUuid}"; private static final String URI_NETWORK_MODIF_WITH_ID = "/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications/{uuid}"; private static final NetworkModificationResult DEFAULT_BUILD_RESULT = createModificationResultWithElementImpact(SimpleImpactType.CREATION, IdentifiableType.LINE, "lineId", Set.of("s1", "s2")).get(); @@ -213,6 +214,9 @@ class NetworkModificationTest { @Autowired private StudyService studyService; + @Autowired + private StudyTestUtils studyTestUtils; + //output destinations private static final String STUDY_UPDATE_DESTINATION = "study.update"; private static final String ELEMENT_UPDATE_DESTINATION = "element.update"; @@ -551,7 +555,7 @@ void testBuild() throws Exception { @Test void testLocalBuildValue() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); - UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyEntity.getId()); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); String userId = "userId"; @@ -581,7 +585,7 @@ void testLocalBuildValue() throws Exception { // Build first node with errors networkModificationResult.get().setApplicationStatus(NetworkModificationResult.ApplicationStatus.WITH_ERRORS); UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -593,13 +597,13 @@ void testLocalBuildValue() throws Exception { checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, rootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, firstRootNetworkUuid).getGlobalBuildStatus()); wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING); // Build second node is OK networkModificationResult.get().setApplicationStatus(NetworkModificationResult.ApplicationStatus.ALL_OK); stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -611,12 +615,12 @@ void testLocalBuildValue() throws Exception { checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNode2Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); - assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, rootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, firstRootNetworkUuid).getGlobalBuildStatus()); wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING); //Build modification node 2, local status should be BUILT and computed one should be BUILT_WITH_ERRORS - assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, rootNetworkUuid).getLocalBuildStatus()); - assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, rootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, firstRootNetworkUuid).getLocalBuildStatus()); + assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, firstRootNetworkUuid).getGlobalBuildStatus()); } @Test @@ -627,7 +631,7 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); - UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyEntity.getId()); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, @@ -647,14 +651,14 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception String bodyJson = mapper.writeValueAsString(body); // update switch on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // update switch on first modification node UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -675,7 +679,7 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception assertThat(csbiListResult.get(0), createMatcherCreatedStudyBasicInfos(studyNameUserIdUuid, "UCTE")); // update switch on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -698,7 +702,7 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception Optional networkModificationResult = createModificationResultWithElementImpact(SimpleImpactType.MODIFICATION, IdentifiableType.SWITCH, "switchId", Set.of("s1", "s2", "s3")); stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -715,10 +719,10 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception assertTrue(requests.stream().anyMatch(r -> r.getPath().matches("/v1/reports"))); // modificationNode2 is still built - assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode1Uuid, rootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode1Uuid, firstRootNetworkUuid).getGlobalBuildStatus()); // modificationNode2 is now invalid - assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, rootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, firstRootNetworkUuid).getGlobalBuildStatus()); } @Test @@ -729,6 +733,7 @@ void testNetworkModificationEquipment() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node 1", userId); UUID modificationNodeUuid = modificationNode.getId(); @@ -743,14 +748,14 @@ void testNetworkModificationEquipment() throws Exception { String bodyJson = mapper.writeValueAsString(body); //update equipment on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); //update equipment UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -770,7 +775,7 @@ void testNetworkModificationEquipment() throws Exception { assertThat(csbiListResponse.get(0), createMatcherCreatedStudyBasicInfos(studyNameUserIdUuid, "UCTE")); // update equipment on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid2) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid2, firstRootNetworkUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -788,6 +793,7 @@ void testCreateGenerator() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -813,14 +819,14 @@ void testCreateGenerator() throws Exception { String bodyJsonCreate = mapper.writeValueAsString(body); // create generator on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) .content(bodyJsonCreate).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // create generator on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(bodyJsonCreate).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -832,7 +838,7 @@ void testCreateGenerator() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, bodyJsonCreate, NETWORK_UUID_STRING, VARIANT_ID); // create generator on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) .content(bodyJsonCreate).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -869,7 +875,7 @@ void testCreateGenerator() throws Exception { body.replace("maxActivePower", "200.0"); String bodyJsonCreateBis = mapper.writeValueAsString(body); when(rootNetworkNodeInfoRepository.existsByStudyUuidAndBuildStatus(studyNameUserIdUuid, BuildStatus.BUILDING)).thenReturn(true); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(bodyJsonCreateBis).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); @@ -880,6 +886,7 @@ void testCreateShuntsCompensator() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -888,14 +895,14 @@ void testCreateShuntsCompensator() throws Exception { String createShuntCompensatorAttributes = "{\"type\":\"" + ModificationType.SHUNT_COMPENSATOR_CREATION + "\",\"shuntCompensatorId\":\"shuntCompensatorId1\",\"shuntCompensatorName\":\"shuntCompensatorName1\",\"voltageLevelId\":\"idVL1\",\"busOrBusbarSectionId\":\"idBus1\"}"; // create shuntCompensator on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) .content(createShuntCompensatorAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // create shuntCompensator on modification node child of root node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(createShuntCompensatorAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -923,7 +930,7 @@ void testCreateShuntsCompensator() throws Exception { when(rootNetworkNodeInfoRepository.existsByStudyUuidAndBuildStatus(studyNameUserIdUuid, BuildStatus.BUILDING)).thenReturn(true); // create shunt compensator on building node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(createShuntCompensatorAttributes2).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); @@ -934,6 +941,7 @@ void testCreateLine() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -951,14 +959,14 @@ void testCreateLine() throws Exception { + "\"voltageLevelId2\":\"idVL2\"," + "\"busOrBusbarSectionId2\":\"idBus2\"}"; // create line on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) .content(createLineAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // create line on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(createLineAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -970,7 +978,7 @@ void testCreateLine() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createLineAttributes, NETWORK_UUID_STRING, VARIANT_ID); // create line on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) .content(createLineAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1012,7 +1020,7 @@ void testCreateLine() throws Exception { rootNetworkNodeInfo1Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILDING)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo1Entity); // create line on building node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(createLineAttributes2).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); @@ -1023,6 +1031,7 @@ void testCreateTwoWindingsTransformer() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -1034,14 +1043,14 @@ void testCreateTwoWindingsTransformer() throws Exception { String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; // create 2WT on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // create 2WT on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1053,7 +1062,7 @@ void testCreateTwoWindingsTransformer() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING, VARIANT_ID); // create 2WT on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1083,7 +1092,7 @@ void testCreateTwoWindingsTransformer() throws Exception { rootNetworkNodeInfo1Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILDING)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo1Entity); // create Two Windings Transformer on building node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(createTwoWindingsTransformerAttributes2).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); @@ -1097,6 +1106,7 @@ void deleteModificationRequest() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); UUID rootNodeUuid = getRootNode(studyUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyUuid, rootNodeUuid, VARIANT_ID, "node 1", userId); createNetworkModificationNode(studyUuid, rootNodeUuid, VARIANT_ID_2, "node 2", userId); @@ -1112,7 +1122,9 @@ void deleteModificationRequest() throws Exception { mockMvc.perform(delete(URI_NETWORK_MODIF, studyUuid1, modificationNode.getId()) .queryParam("uuids", node3.getId().toString()) .header(USER_ID_HEADER, userId)) - .andExpect(status().isNotFound()); + .andExpect(status().isForbidden()); + checkEquipmentDeletingMessagesReceived(studyUuid1, modificationNode.getId()); + checkEquipmentDeletingFinishedMessagesReceived(studyUuid1, modificationNode.getId()); UUID modificationUuid = UUID.randomUUID(); mockMvc.perform(delete(URI_NETWORK_MODIF, studyUuid, modificationNode.getId()) @@ -1141,6 +1153,7 @@ void testUpdateLines() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -1157,13 +1170,13 @@ void testUpdateLines() throws Exception { // change line status on root node (not allowed) UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) .content(bodyJsonCreate1).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // lockout line - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(bodyJsonCreate1).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1177,7 +1190,7 @@ void testUpdateLines() throws Exception { bodyLineInfos.put("equipmentId", "lineFailedId"); String bodyJsonCreate2 = mapper.writeValueAsString(bodyLineInfos); stubPostId = wireMockUtils.stubNetworkModificationPostWithError(bodyJsonCreate2); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(bodyJsonCreate2).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isBadRequest()); @@ -1190,7 +1203,7 @@ void testUpdateLines() throws Exception { bodyLineInfos.put("action", "trip"); String bodyJsonCreate3 = mapper.writeValueAsString(bodyLineInfos); stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(bodyJsonCreate3).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1204,7 +1217,7 @@ void testUpdateLines() throws Exception { bodyLineInfos.put("equipmentId", "lineFailedId"); String bodyJsonCreate4 = mapper.writeValueAsString(bodyLineInfos); stubPostId = wireMockUtils.stubNetworkModificationPostWithError(bodyJsonCreate4); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(bodyJsonCreate4).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isBadRequest()); @@ -1217,7 +1230,7 @@ void testUpdateLines() throws Exception { bodyLineInfos.put("action", "energiseEndOne"); String bodyJsonCreate5 = mapper.writeValueAsString(bodyLineInfos); stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(bodyJsonCreate5).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1231,7 +1244,7 @@ void testUpdateLines() throws Exception { bodyLineInfos.put("equipmentId", "lineFailedId"); String bodyJsonCreate6 = mapper.writeValueAsString(bodyLineInfos); stubPostId = wireMockUtils.stubNetworkModificationPostWithError(bodyJsonCreate6); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(bodyJsonCreate6).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isBadRequest()); @@ -1244,7 +1257,7 @@ void testUpdateLines() throws Exception { bodyLineInfos.put("action", "switchOn"); String bodyJsonCreate7 = mapper.writeValueAsString(bodyLineInfos); stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(bodyJsonCreate7).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1258,7 +1271,7 @@ void testUpdateLines() throws Exception { bodyLineInfos.put("equipmentId", "lineFailedId"); String bodyJsonCreate8 = mapper.writeValueAsString(bodyLineInfos); stubPostId = wireMockUtils.stubNetworkModificationPostWithError(bodyJsonCreate8); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(bodyJsonCreate8).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isBadRequest()); @@ -1269,7 +1282,7 @@ void testUpdateLines() throws Exception { // switch on line on second modification node String bodyJsonCreate9 = bodyJsonCreate7; stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) .content(bodyJsonCreate9).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1286,6 +1299,7 @@ void testCreateLoad() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -1300,14 +1314,14 @@ void testCreateLoad() throws Exception { String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; // create load on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) .content(createLoadAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // create load on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(createLoadAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1319,7 +1333,7 @@ void testCreateLoad() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID); // create load on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) .content(createLoadAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1350,7 +1364,7 @@ void testCreateLoad() throws Exception { rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo3Entity); // create load on building node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode3Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode3Uuid, firstRootNetworkUuid) .content(createLoadAttributes2).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); @@ -1361,6 +1375,7 @@ void testModifyLoad() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -1372,14 +1387,14 @@ void testModifyLoad() throws Exception { String loadModificationAttributes = "{\"type\":\"" + ModificationType.LOAD_MODIFICATION + "\",\"equipmentId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"AUXILIARY\",\"activePower\":\"100.0\"}"; // modify load on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) .content(loadModificationAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // modify load on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(loadModificationAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1391,7 +1406,7 @@ void testModifyLoad() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, loadModificationAttributes, NETWORK_UUID_STRING, VARIANT_ID); // modify load on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid2) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid2, firstRootNetworkUuid) .content(loadModificationAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1421,6 +1436,7 @@ void testModifyEquipment() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); UUID modificationNodeUuid = modificationNode.getId(); @@ -1429,14 +1445,14 @@ void testModifyEquipment() throws Exception { // modify generator on root node (not allowed) String equipmentModificationAttribute = "{\"type\":\"" + ModificationType.GENERATOR_MODIFICATION + "\",\"equipmentId\":\"equipmentId\"}"; - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) .content(equipmentModificationAttribute).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // modify generator on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(equipmentModificationAttribute).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1448,7 +1464,7 @@ void testModifyEquipment() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, equipmentModificationAttribute, NETWORK_UUID_STRING, VARIANT_ID); // modify generator on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid2) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid2, firstRootNetworkUuid) .content(equipmentModificationAttribute).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1478,6 +1494,7 @@ void testCreateSubstation() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -1489,14 +1506,14 @@ void testCreateSubstation() throws Exception { String createSubstationAttributes = "{\"type\":\"" + ModificationType.SUBSTATION_CREATION + "\",\"substationId\":\"substationId1\",\"substationName\":\"substationName1\",\"country\":\"AD\"}"; // create substation on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) .content(createSubstationAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // create substation on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(createSubstationAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1508,7 +1525,7 @@ void testCreateSubstation() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createSubstationAttributes, NETWORK_UUID_STRING, VARIANT_ID); // create substation on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) .content(createSubstationAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1538,7 +1555,7 @@ void testCreateSubstation() throws Exception { rootNetworkNodeInfo1Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILDING)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo1Entity); // create substation on building node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(createSubstationAttributes2).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); @@ -1549,6 +1566,7 @@ void testCreateVoltageLevel() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node 1", userId); UUID modificationNode1Uuid = modificationNode1.getId(); @@ -1560,14 +1578,14 @@ void testCreateVoltageLevel() throws Exception { + ",\"nominalVoltage\":\"379.1\", \"substationId\":\"s1\"}"; // create voltage level on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) .content(createVoltageLevelAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // create voltage level UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(createVoltageLevelAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1579,7 +1597,7 @@ void testCreateVoltageLevel() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createVoltageLevelAttributes, NETWORK_UUID_STRING, VARIANT_ID); // create voltage level on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) .content(createVoltageLevelAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1611,7 +1629,7 @@ void testCreateVoltageLevel() throws Exception { rootNetworkNodeInfo1Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILDING)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo1Entity); // create voltage level on building node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(createVoltageLevelAttributes2).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); @@ -1622,6 +1640,7 @@ void testLineSplitWithVoltageLevel() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); @@ -1640,7 +1659,7 @@ void testLineSplitWithVoltageLevel() throws Exception { String lineSplitWoVLasJSON = mapper.writeValueAsString(lineSplitWoVL); UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(lineSplitWoVLasJSON).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1665,7 +1684,7 @@ void testLineSplitWithVoltageLevel() throws Exception { String badBody = "{\"type\":\"" + ModificationType.LINE_SPLIT_WITH_VOLTAGE_LEVEL + "\",\"bogus\":\"bogus\"}"; stubPostId = wireMockUtils.stubNetworkModificationPostWithBodyAndError(badBody); stubPutId = wireMockUtils.stubNetworkModificationPutWithBodyAndError(MODIFICATION_UUID, badBody); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(badBody).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpectAll( @@ -1690,6 +1709,7 @@ void testLineAttachToVoltageLevel() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); @@ -1701,7 +1721,7 @@ void testLineAttachToVoltageLevel() throws Exception { createVoltageLevelAttributes + ",\"attachmentLine\":" + createLineAttributes + "}"; UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(createLineAttachToVoltageLevelAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1729,13 +1749,14 @@ void testLinesAttachToSplitLines() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); String createLinesAttachToSplitLinesAttributes = "{\"type\":\"" + ModificationType.LINES_ATTACH_TO_SPLIT_LINES + "\",\"lineToAttachTo1Id\":\"line1\",\"lineToAttachTo2Id\":\"line2\",\"attachedLineId\":\"line3\",\"voltageLevelId\":\"vl1\",\"bbsBusId\":\"v1bbs\",\"replacingLine1Id\":\"replacingLine1Id\",\"replacingLine1Name\":\"replacingLine1Name\",\"replacingLine2Id\":\"replacingLine2Id\",\"replacingLine2Name\":\"replacingLine2Name\"}"; UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(createLinesAttachToSplitLinesAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1760,7 +1781,7 @@ void testLinesAttachToSplitLines() throws Exception { String badBody = "{\"type\":\"" + ModificationType.LINES_ATTACH_TO_SPLIT_LINES + "\",\"bogus\":\"bogus\"}"; stubPostId = wireMockUtils.stubNetworkModificationPostWithBodyAndError(badBody); stubPutId = wireMockUtils.stubNetworkModificationPutWithBodyAndError(MODIFICATION_UUID, badBody); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(badBody).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isBadRequest()); @@ -1785,12 +1806,13 @@ void testScaling(ModificationType scalingType) throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(requestBody).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1814,7 +1836,7 @@ void testScaling(ModificationType scalingType) throws Exception { // test with errors stubPostId = wireMockUtils.stubNetworkModificationPostWithBodyAndError(requestBody); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(requestBody).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().is4xxClientError()); @@ -1837,6 +1859,7 @@ void testDeleteVoltageLevelOnline() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); @@ -1844,7 +1867,7 @@ void testDeleteVoltageLevelOnline() throws Exception { String createDeleteVoltageLevelOnlineAttributes = "{\"type\":\"" + ModificationType.DELETE_VOLTAGE_LEVEL_ON_LINE + "\",\"lineToAttachTo1Id\":\"line1\",\"lineToAttachTo2Id\":\"line2\",\"replacingLine1Id\":\"replacingLine1Id\",\"replacingLine1Name\":\"replacingLine1Name\"}"; UUID stubIdPost = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(createDeleteVoltageLevelOnlineAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1867,7 +1890,7 @@ void testDeleteVoltageLevelOnline() throws Exception { String badBody = "{\"type\":\"" + ModificationType.DELETE_VOLTAGE_LEVEL_ON_LINE + "\",\"bogus\":\"bogus\"}"; UUID stubIdPostErr = wireMockUtils.stubNetworkModificationPostWithBodyAndError(badBody); UUID stubIdPutErr = wireMockUtils.stubNetworkModificationPutWithBodyAndError(MODIFICATION_UUID, badBody); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid).header(USER_ID_HEADER, userId) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid).header(USER_ID_HEADER, userId) .content(badBody).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isBadRequest()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); @@ -1888,13 +1911,14 @@ void testDeleteAttachingline() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); String createDeleteAttachingLineAttributes = "{\"type\":\"" + ModificationType.DELETE_ATTACHING_LINE + "\",\"lineToAttachTo1Id\":\"line1\",\"lineToAttachTo2Id\":\"line2\",\"attachedLineId\":\"line3\",\"replacingLine1Id\":\"replacingLine1Id\",\"replacingLine1Name\":\"replacingLine1Name\"}"; UUID stubIdPost = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(createDeleteAttachingLineAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1917,7 +1941,7 @@ void testDeleteAttachingline() throws Exception { String badBody = "{\"type\":\"" + ModificationType.DELETE_ATTACHING_LINE + "\",\"bogus\":\"bogus\"}"; UUID stubIdPostErr = wireMockUtils.stubNetworkModificationPostWithBodyAndError(badBody); UUID stubIdPutErr = wireMockUtils.stubNetworkModificationPutWithBodyAndError(MODIFICATION_UUID, badBody); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(badBody).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isBadRequest()); @@ -1939,6 +1963,7 @@ void testReorderModification() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node", userId); @@ -1954,8 +1979,8 @@ void testReorderModification() throws Exception { .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); // switch the 2 modifications order (modification1 is set at the end, after modification2) - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}", - studyNameUserIdUuid, modificationNodeUuid, modification1).header(USER_ID_HEADER, "userId")) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?rootNetworkUuid={rootNetworkUuid}", + studyNameUserIdUuid, modificationNodeUuid, modification1, firstRootNetworkUuid).header(USER_ID_HEADER, "userId")) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); @@ -1977,8 +2002,8 @@ void testReorderModification() throws Exception { expectedBody); // switch back the 2 modifications order (modification1 is set before modification2) - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?beforeUuid={modificationID2}", - studyNameUserIdUuid, modificationNodeUuid, modification1, modification2).header(USER_ID_HEADER, "userId")) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?beforeUuid={modificationID2}&rootNetworkUuid={rootNetworkUuid}", + studyNameUserIdUuid, modificationNodeUuid, modification1, modification2, firstRootNetworkUuid).header(USER_ID_HEADER, "userId")) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); @@ -2003,6 +2028,7 @@ void testReorderModificationErrorCase() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node", userId); @@ -2011,17 +2037,20 @@ void testReorderModificationErrorCase() throws Exception { UUID modification1 = UUID.randomUUID(); UUID modification2 = UUID.randomUUID(); UUID studyNameUserIdUuid1 = UUID.randomUUID(); + UUID rootNetworkUuid1 = UUID.randomUUID(); UUID nodeIdUuid1 = UUID.randomUUID(); - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?beforeUuid={modificationID2}", - studyNameUserIdUuid, nodeIdUuid1, modification1, modification2).header(USER_ID_HEADER, "userId")) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?beforeUuid={modificationID2}&rootNetworkUuid={rootNetworkUuid}", + studyNameUserIdUuid, nodeIdUuid1, modification1, modification2, firstRootNetworkUuid).header(USER_ID_HEADER, "userId")) .andExpect(status().isNotFound()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, nodeIdUuid1); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, nodeIdUuid1); - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?beforeUuid={modificationID2}", - studyNameUserIdUuid1, modificationNodeUuid, modification1, modification2).header(USER_ID_HEADER, "userId")) - .andExpect(status().isNotFound()); + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?beforeUuid={modificationID2}&rootNetworkUuid={rootNetworkUuid}", + studyNameUserIdUuid1, modificationNodeUuid, modification1, modification2, rootNetworkUuid1).header(USER_ID_HEADER, "userId")) + .andExpect(status().isForbidden()); + checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid1, modificationNodeUuid); + checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid1, modificationNodeUuid); } @Test @@ -2029,6 +2058,7 @@ void testDuplicateModification() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); UUID rootNodeUuid = getRootNode(studyUuid).getId(); NetworkModificationNode node1 = createNetworkModificationNode(studyUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "New node 1", "userId"); @@ -2044,8 +2074,8 @@ void testDuplicateModification() throws Exception { .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); // duplicate 2 modifications in node1 - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY", - studyUuid, nodeUuid1) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY&rootNetworkUuid={rootNetworkUuid}", + studyUuid, nodeUuid1, firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) @@ -2078,8 +2108,8 @@ void testDuplicateModification() throws Exception { .withBody(mapper.writeValueAsString(Optional.of(NetworkModificationResult.builder().build()))) .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY", - studyUuid, nodeUuid1) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY&rootNetworkUuid={rootNetworkUuid}", + studyUuid, nodeUuid1, firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) @@ -2109,6 +2139,7 @@ void testDuplicateModification() throws Exception { void testDuplicateModificationErrorCase() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); UUID rootNodeUuid = getRootNode(studyUuid).getId(); createNetworkModificationNode(studyUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "New node 1", "userId"); UUID modification1 = UUID.randomUUID(); @@ -2116,16 +2147,16 @@ void testDuplicateModificationErrorCase() throws Exception { String modificationUuidListBody = mapper.writeValueAsString(Arrays.asList(modification1, modification2)); // Random/bad studyId error case - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY", - UUID.randomUUID(), rootNodeUuid) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY&rootNetworkUuid={rootNetworkUuid}", + UUID.randomUUID(), rootNodeUuid, firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) .andExpect(status().isNotFound()); // Random/bad nodeId error case - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY", - studyUuid, UUID.randomUUID()) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY&rootNetworkUuid={rootNetworkUuid}", + studyUuid, UUID.randomUUID(), firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) @@ -2138,6 +2169,7 @@ void testCutAndPasteModification() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); UUID rootNodeUuid = getRootNode(studyUuid).getId(); NetworkModificationNode node1 = createNetworkModificationNode(studyUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "New node 1", userId); @@ -2156,8 +2188,8 @@ void testCutAndPasteModification() throws Exception { .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); // move 2 modifications within node 1 - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?originNodeUuid={originNodeUuid}&action=MOVE", - studyUuid, nodeUuid1, nodeUuid1) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?originNodeUuid={originNodeUuid}&action=MOVE&rootNetworkUuid={rootNetworkUuid}", + studyUuid, nodeUuid1, nodeUuid1, firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) @@ -2181,8 +2213,8 @@ void testCutAndPasteModification() throws Exception { expectedBody); // move 2 modifications from node1 to node2 - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?originNodeUuid={originNodeUuid}&action=MOVE", - studyUuid, nodeUuid2, nodeUuid1) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?originNodeUuid={originNodeUuid}&action=MOVE&rootNetworkUuid={rootNetworkUuid}", + studyUuid, nodeUuid2, nodeUuid1, firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) @@ -2212,8 +2244,8 @@ void testCutAndPasteModification() throws Exception { expectedBody); // move modification without defining originNodeUuid - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=MOVE", - studyUuid, nodeUuid1) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=MOVE&rootNetworkUuid={rootNetworkUuid}", + studyUuid, nodeUuid1, firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) @@ -2233,16 +2265,16 @@ void testCutAndPasteModificationErrorCase() throws Exception { String modificationUuidListBody = mapper.writeValueAsString(Arrays.asList(modification1, modification2)); // Random/bad studyId error case - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?originNodeUuid={originNodeUuid}&action=MOVE", - UUID.randomUUID(), rootNodeUuid, UUID.randomUUID()) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?originNodeUuid={originNodeUuid}&action=MOVE&rootNetworkUuid={rootNetworkUuid}", + UUID.randomUUID(), rootNodeUuid, UUID.randomUUID(), UUID.randomUUID()) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) .andExpect(status().isNotFound()); // Random/bad nodeId error case - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?originNodeUuid={originNodeUuid}&action=MOVE", - studyUuid, UUID.randomUUID(), UUID.randomUUID()) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?originNodeUuid={originNodeUuid}&action=MOVE&rootNetworkUuid={rootNetworkUuid}", + studyUuid, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) @@ -2254,6 +2286,7 @@ void testDeleteEquipment() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -2270,14 +2303,14 @@ void testDeleteEquipment() throws Exception { String bodyJson = mapper.writeValueAsString(body); // delete equipment on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // delete equipment on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2289,7 +2322,7 @@ void testDeleteEquipment() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, bodyJson, NETWORK_UUID_STRING, VARIANT_ID); // delete equipment on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2317,8 +2350,8 @@ void testDeleteEquipment() throws Exception { void testNodesInvalidation(final MockWebServer server) throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); - UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", BuildStatus.BUILT, userId); UUID modificationNode1Uuid = modificationNode1.getId(); @@ -2377,7 +2410,7 @@ void testNodesInvalidation(final MockWebServer server) throws Exception { Map createLoadInfos = Map.of("type", ModificationType.LOAD_CREATION, "equipmentId", "loadId"); String jsonCreateLoadInfos = mapper.writeValueAsString(createLoadInfos); stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2386,7 +2419,7 @@ void testNodesInvalidation(final MockWebServer server) throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode3Uuid, rootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode3Uuid, firstRootNetworkUuid).getGlobalBuildStatus()); wireMockUtils.verifyNetworkModificationPost(stubUuid, jsonCreateLoadInfos, NETWORK_UUID_STRING); requests = TestUtils.getRequestsWithBodyDone(1, server); @@ -2398,6 +2431,7 @@ void testRemoveLoadFlowComputationReport(final MockWebServer server) throws Exce String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", BuildStatus.BUILT, userId); UUID modificationNode1Uuid = modificationNode1.getId(); @@ -2435,7 +2469,7 @@ void testRemoveLoadFlowComputationReport(final MockWebServer server) throws Exce // add this modification to the node => invalidate the LF UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2459,7 +2493,7 @@ void testRemoveLoadFlowComputationReport(final MockWebServer server) throws Exce @Test void testUpdateOfBuildStatus() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); - UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyEntity.getId()); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); String userId = "userId"; @@ -2472,7 +2506,7 @@ void testUpdateOfBuildStatus() throws Exception { // Create network modification on NOT_BUILT modification node UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2481,7 +2515,7 @@ void testUpdateOfBuildStatus() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, rootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, firstRootNetworkUuid).getGlobalBuildStatus()); wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING, VARIANT_ID); // Mark the node status as built @@ -2493,7 +2527,7 @@ void testUpdateOfBuildStatus() throws Exception { Optional networkModificationResult = createModificationResultWithElementImpact(SimpleImpactType.CREATION, IdentifiableType.LOAD, "loadId", Set.of("s1")); stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2504,13 +2538,13 @@ void testUpdateOfBuildStatus() throws Exception { checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, rootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, firstRootNetworkUuid).getGlobalBuildStatus()); wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING, VARIANT_ID); // Built with warnings networkModificationResult.get().setApplicationStatus(NetworkModificationResult.ApplicationStatus.WITH_WARNINGS); stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2521,13 +2555,13 @@ void testUpdateOfBuildStatus() throws Exception { checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - assertEquals(BuildStatus.BUILT_WITH_WARNING, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, rootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.BUILT_WITH_WARNING, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, firstRootNetworkUuid).getGlobalBuildStatus()); wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING); // Built with errors networkModificationResult.get().setApplicationStatus(NetworkModificationResult.ApplicationStatus.WITH_ERRORS); stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2538,7 +2572,7 @@ void testUpdateOfBuildStatus() throws Exception { checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, rootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, firstRootNetworkUuid).getGlobalBuildStatus()); wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING); } @@ -2864,6 +2898,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU void testCreateModificationWithErrors() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); String userId = "userId"; NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, @@ -2875,7 +2910,7 @@ void testCreateModificationWithErrors() throws Exception { // Create network modification on first modification node UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2889,7 +2924,7 @@ void testCreateModificationWithErrors() throws Exception { // String message error String contentErrorMessage = "Internal Server Error"; stubId = wireMockUtils.stubNetworkModificationPostWithError(jsonCreateLoadInfos); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpectAll(status().isBadRequest(), content().string(contentErrorMessage)); @@ -2899,7 +2934,7 @@ void testCreateModificationWithErrors() throws Exception { // Json message error stubId = wireMockUtils.stubNetworkModificationPostWithError(jsonCreateLoadInfos, String.format("{\"message\" : \"%s\"}", contentErrorMessage)); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpectAll(status().isBadRequest(), content().string(contentErrorMessage)); @@ -2910,7 +2945,7 @@ void testCreateModificationWithErrors() throws Exception { // Bad json message error contentErrorMessage = String.format("{\"foo\" : \"%s\"}", contentErrorMessage); stubId = wireMockUtils.stubNetworkModificationPostWithError(jsonCreateLoadInfos, contentErrorMessage); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) + mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpectAll(status().isBadRequest(), content().string(contentErrorMessage)); diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java index 47b792aec..724f271b8 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java @@ -47,6 +47,7 @@ import org.gridsuite.study.server.repository.rootnetwork.RootNetworkRepository; import org.gridsuite.study.server.service.*; import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService; +import org.gridsuite.study.server.utils.StudyTestUtils; import org.gridsuite.study.server.utils.TestUtils; import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch; import org.jetbrains.annotations.NotNull; @@ -198,6 +199,8 @@ class NetworkModificationTreeTest { private RootNetworkService rootNetworkService; @Autowired private StudyService studyService; + @Autowired + private StudyTestUtils studyTestUtils; @BeforeEach void setUp(final MockWebServer server) { @@ -1173,6 +1176,7 @@ void testGetNetworkModificationsNode() throws Exception { void testGetNetworkModificationsToRestoreByNode() throws Exception { String userId = "userId"; RootNode root = createRoot(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(root.getStudyId()); NetworkModificationNode node = buildNetworkModificationNode("modification node 1", "", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT); createNode(root.getStudyId(), root, node, userId); @@ -1188,7 +1192,7 @@ void testGetNetworkModificationsToRestoreByNode() throws Exception { node = buildNetworkModificationNode("modification node 3", "", UUID.fromString(MODIFICATION_GROUP_UUID_STRING), VARIANT_ID, null, null, null, null, null, null, null, BuildStatus.BUILT); createNode(root.getStudyId(), root, node, userId); - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications?uuids={modificationID1}&stashed=false", root.getStudyId(), node.getId(), MODIFICATION1_UUID_STRING) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications?uuids={modificationID1}&stashed=false&rootNetworkUuid={rootNetworkUuid}", root.getStudyId(), node.getId(), MODIFICATION1_UUID_STRING, firstRootNetworkUuid) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1211,6 +1215,7 @@ void testGetNetworkModificationsToRestoreByNode() throws Exception { void testGetNetworkModificationsToStashByNode() throws Exception { String userId = "userId"; RootNode root = createRoot(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(root.getStudyId()); NetworkModificationNode node = buildNetworkModificationNode("modification node 1", "", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT); createNode(root.getStudyId(), root, node, userId); @@ -1226,7 +1231,7 @@ void testGetNetworkModificationsToStashByNode() throws Exception { node = buildNetworkModificationNode("modification node 3", "", UUID.fromString(MODIFICATION_GROUP_UUID_STRING), VARIANT_ID, null, null, null, null, null, null, null, BuildStatus.BUILT); createNode(root.getStudyId(), root, node, userId); - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications?uuids={modificationID1}&stashed=true", root.getStudyId(), node.getId(), MODIFICATION1_UUID_STRING) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications?uuids={modificationID1}&stashed=true&rootNetworkUuid={rootNetworkUuid}", root.getStudyId(), node.getId(), MODIFICATION1_UUID_STRING, firstRootNetworkUuid) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationUnitTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationUnitTest.java index 39c49bd07..c646ff1ca 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationUnitTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationUnitTest.java @@ -185,7 +185,8 @@ void deactivateNetworkModificationTest() { } private void updateNetworkModificationActivationStatus(List networkModificationUuids, UUID nodeWithModification, List childrenNodes, List nodesToUnbuild, boolean activated) { - studyController.updateNetworkModificationsActivation(studyUuid, node1Uuid, networkModificationUuids, activated, "userId"); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); + studyController.updateNetworkModificationsActivation(studyUuid, node1Uuid, networkModificationUuids, firstRootNetworkUuid, activated, "userId"); checkModificationUpdatedMessageReceived(studyUuid, nodeWithModification, childrenNodes, NotificationService.MODIFICATIONS_UPDATING_IN_PROGRESS); checkUpdateBuildStateMessageReceived(studyUuid, nodesToUnbuild); diff --git a/src/test/java/org/gridsuite/study/server/StudyTest.java b/src/test/java/org/gridsuite/study/server/StudyTest.java index 2dfd24d94..5dcae81bb 100644 --- a/src/test/java/org/gridsuite/study/server/StudyTest.java +++ b/src/test/java/org/gridsuite/study/server/StudyTest.java @@ -169,7 +169,7 @@ class StudyTest { private static final String CASE_NAME = "DefaultCaseName"; private static final UUID EMPTY_MODIFICATION_GROUP_UUID = UUID.randomUUID(); private static final String STUDY_CREATION_ERROR_MESSAGE = "Une erreur est survenue lors de la création de l'étude"; - private static final String URI_NETWORK_MODIF = "/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications"; + private static final String URI_NETWORK_MODIF = "/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications?rootNetworkUuid={rootNetworkUuid}"; private static final String CASE_FORMAT = "caseFormat"; private static final String NO_PARAMS_IN_PROFILE_USER_ID = "noParamInProfileUser"; private static final String USER_PROFILE_NO_PARAMS_JSON = "{\"id\":\"97bb1890-a90c-43c3-a004-e631246d42d6\",\"name\":\"Profile No params\"}"; @@ -1419,7 +1419,7 @@ void testCreateStudyWithDefaultLoadflowUserHasValidParamsInProfile(final MockWeb createStudy(mockWebServer, VALID_PARAMS_IN_PROFILE_USER_ID, CASE_UUID, PROFILE_LOADFLOW_VALID_PARAMETERS_UUID_STRING, true); } - private void testDuplicateStudy(final MockWebServer mockWebServer, UUID study1Uuid) throws Exception { + private void testDuplicateStudy(final MockWebServer mockWebServer, UUID study1Uuid, UUID rootNetworkUuid) throws Exception { String userId = "userId"; RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); @@ -1430,7 +1430,7 @@ private void testDuplicateStudy(final MockWebServer mockWebServer, UUID study1Uu String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId()) + mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId(), rootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(createTwoWindingsTransformerAttributes) .header(USER_ID_HEADER, "userId")) @@ -1446,7 +1446,7 @@ private void testDuplicateStudy(final MockWebServer mockWebServer, UUID study1Uu String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId()) + mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId(), rootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(createLoadAttributes) .header(USER_ID_HEADER, "userId")) @@ -1483,24 +1483,26 @@ private void testDuplicateStudy(final MockWebServer mockWebServer, UUID study1Uu @Test void testDuplicateStudyWithParametersUuid(final MockWebServer mockWebServer) throws Exception { UUID study1Uuid = createStudy(mockWebServer, "userId", CASE_UUID); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid); StudyEntity studyEntity = studyRepository.findById(study1Uuid).orElseThrow(); studyEntity.setLoadFlowParametersUuid(UUID.randomUUID()); studyEntity.setSecurityAnalysisParametersUuid(UUID.randomUUID()); studyEntity.setVoltageInitParametersUuid(UUID.randomUUID()); studyEntity.setSensitivityAnalysisParametersUuid(UUID.randomUUID()); studyRepository.save(studyEntity); - testDuplicateStudy(mockWebServer, study1Uuid); + testDuplicateStudy(mockWebServer, study1Uuid, firstRootNetworkUuid); } @Test void testDuplicateStudyWithoutParametersUuid(final MockWebServer mockWebServer) throws Exception { UUID study1Uuid = createStudy(mockWebServer, "userId", CASE_UUID); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid); StudyEntity studyEntity = studyRepository.findById(study1Uuid).orElseThrow(); studyEntity.setLoadFlowParametersUuid(null); studyEntity.setSecurityAnalysisParametersUuid(null); studyEntity.setSensitivityAnalysisParametersUuid(null); studyRepository.save(studyEntity); - testDuplicateStudy(mockWebServer, study1Uuid); + testDuplicateStudy(mockWebServer, study1Uuid, firstRootNetworkUuid); } @Test @@ -1649,6 +1651,7 @@ private StudyEntity duplicateStudy(final MockWebServer server, UUID studyUuid) t void testCutAndPasteNode(final MockWebServer mockWebServer) throws Exception { String userId = "userId"; UUID study1Uuid = createStudy(mockWebServer, "userId", CASE_UUID); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid); RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); @@ -1667,7 +1670,7 @@ void testCutAndPasteNode(final MockWebServer mockWebServer) throws Exception { // add modification on node "node1" String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; UUID stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId()) + mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId(), firstRootNetworkUuid) .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1681,7 +1684,7 @@ void testCutAndPasteNode(final MockWebServer mockWebServer) throws Exception { // add modification on node "node2" String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId()) + mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId(), firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(createLoadAttributes) .header(USER_ID_HEADER, userId)) @@ -1982,6 +1985,7 @@ void testCutAndPasteSubtree(final MockWebServer server) throws Exception { void testDuplicateNode(final MockWebServer mockWebServer) throws Exception { String userId = "userId"; UUID study1Uuid = createStudy(mockWebServer, userId, CASE_UUID); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid); RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); @@ -1992,7 +1996,7 @@ void testDuplicateNode(final MockWebServer mockWebServer) throws Exception { // add modification on node "node1" String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; UUID stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId()) + mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId(), firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(createTwoWindingsTransformerAttributes) .header(USER_ID_HEADER, "userId")) @@ -2007,7 +2011,7 @@ void testDuplicateNode(final MockWebServer mockWebServer) throws Exception { // add modification on node "node2" String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId()) + mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId(), firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(createLoadAttributes) .header(USER_ID_HEADER, "userId")) @@ -2096,7 +2100,7 @@ void testDuplicateNode(final MockWebServer mockWebServer) throws Exception { void testDuplicateSubtree(final MockWebServer server) throws Exception { String userId = "userId"; UUID study1Uuid = createStudy(server, userId, CASE_UUID); - UUID rootNetworkUuid = rootNetworkRepository.findAllByStudyId(study1Uuid).stream().findFirst().orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)).getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid); RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); @@ -2116,7 +2120,7 @@ void testDuplicateSubtree(final MockWebServer server) throws Exception { // add modification on node "node1" (not built) -> invalidation of node 3 String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; UUID stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId()) + mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId(), firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(createTwoWindingsTransformerAttributes) .header(USER_ID_HEADER, "userId")) @@ -2129,14 +2133,14 @@ void testDuplicateSubtree(final MockWebServer server) throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubUuid, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING, VARIANT_ID); // Invalidation node 3 - assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(node3.getId(), rootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(node3.getId(), firstRootNetworkUuid).getGlobalBuildStatus()); Set requests = TestUtils.getRequestsWithBodyDone(1, server); assertEquals(1, requests.stream().filter(r -> r.getPath().matches("/v1/reports")).count()); // add modification on node "node2" String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId()) + mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId(), firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(createLoadAttributes) .header(USER_ID_HEADER, "userId")) @@ -2148,7 +2152,7 @@ void testDuplicateSubtree(final MockWebServer server) throws Exception { checkElementUpdatedMessageSent(study1Uuid, userId); wireMockUtils.verifyNetworkModificationPostWithVariant(stubUuid, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); - rootNetworkNodeInfoService.updateRootNetworkNode(node2.getId(), rootNetworkUuid, + rootNetworkNodeInfoService.updateRootNetworkNode(node2.getId(), firstRootNetworkUuid, RootNetworkNodeInfo.builder() .nodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)) .loadFlowResultUuid(UUID.randomUUID()) @@ -2218,9 +2222,9 @@ void testDuplicateSubtree(final MockWebServer server) throws Exception { .count()); //node2 should be built - assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(node2.getId(), rootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(node2.getId(), firstRootNetworkUuid).getGlobalBuildStatus()); //duplicated node2 should now be not built - assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(nodesAfterDuplication.get(1), rootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(nodesAfterDuplication.get(1), firstRootNetworkUuid).getGlobalBuildStatus()); //try copy non-existing node and expect not found mockMvc.perform(post(STUDIES_URL + @@ -2241,6 +2245,7 @@ void testDuplicateSubtree(final MockWebServer server) throws Exception { void testDuplicateNodeBetweenStudies(final MockWebServer mockWebServer) throws Exception { String userId = "userId"; UUID study1Uuid = createStudy(mockWebServer, userId, CASE_UUID); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid); RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); @@ -2254,7 +2259,7 @@ void testDuplicateNodeBetweenStudies(final MockWebServer mockWebServer) throws E // add modification on study 1 node "node1" UUID stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; - mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId()) + mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId(), firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(createTwoWindingsTransformerAttributes) .header(USER_ID_HEADER, "userId")) @@ -2269,7 +2274,7 @@ void testDuplicateNodeBetweenStudies(final MockWebServer mockWebServer) throws E // add modification on node "node2" stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; - mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId()) + mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId(), firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(createLoadAttributes) .header(USER_ID_HEADER, "userId")) From 7ccf5dec20a9a4a513cb799136df1e8f4b7d7db2 Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Tue, 17 Dec 2024 10:22:04 +0100 Subject: [PATCH 02/17] fix: creating modifications now update all root network networks Signed-off-by: LE SAULNIER Kevin --- .../study/server/StudyController.java | 20 +- .../study/server/service/StudyService.java | 75 +++-- .../study/server/NetworkModificationTest.java | 265 ++++++++---------- .../server/NetworkModificationUnitTest.java | 3 +- 4 files changed, 169 insertions(+), 194 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/StudyController.java b/src/main/java/org/gridsuite/study/server/StudyController.java index 608363041..078c36ef1 100644 --- a/src/main/java/org/gridsuite/study/server/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/StudyController.java @@ -572,10 +572,9 @@ public ResponseEntity moveModification(@PathVariable("studyUuid") UUID stu @PathVariable("nodeUuid") UUID nodeUuid, @PathVariable("modificationUuid") UUID modificationUuid, @Nullable @Parameter(description = "move before, if no value move to end") @RequestParam(value = "beforeUuid") UUID beforeUuid, - @Parameter(description = "active root network uuid - will apply iteratively modifications for this root network only") @RequestParam(value = "rootNetworkUuid") UUID rootNetworkUuid, @RequestHeader(HEADER_USER_ID) String userId) { studyService.assertCanUpdateModifications(studyUuid, nodeUuid); - studyService.moveModifications(studyUuid, nodeUuid, nodeUuid, rootNetworkUuid, List.of(modificationUuid), beforeUuid, userId); + studyService.moveModifications(studyUuid, nodeUuid, nodeUuid, List.of(modificationUuid), beforeUuid, userId); return ResponseEntity.ok().build(); } @@ -586,11 +585,9 @@ public ResponseEntity moveOrCopyModifications(@PathVariable("studyUuid") U @PathVariable("nodeUuid") UUID nodeUuid, @RequestParam("action") StudyConstants.ModificationsActionType action, @Nullable @RequestParam("originNodeUuid") UUID originNodeUuid, - @Parameter(description = "active root network uuid - will apply iteratively modifications for this root network only") @RequestParam(value = "rootNetworkUuid") UUID rootNetworkUuid, @RequestBody List modificationsToCopyUuidList, @RequestHeader(HEADER_USER_ID) String userId) { studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid); - rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkUuid); studyService.assertCanUpdateModifications(studyUuid, nodeUuid); if (originNodeUuid != null) { studyService.assertIsNodeExist(studyUuid, originNodeUuid); @@ -598,10 +595,10 @@ public ResponseEntity moveOrCopyModifications(@PathVariable("studyUuid") U } switch (action) { case COPY, INSERT: - studyService.createModifications(studyUuid, nodeUuid, rootNetworkUuid, modificationsToCopyUuidList, userId, action); + studyService.createModifications(studyUuid, nodeUuid, modificationsToCopyUuidList, userId, action); break; case MOVE: - studyService.moveModifications(studyUuid, nodeUuid, originNodeUuid, rootNetworkUuid, modificationsToCopyUuidList, null, userId); + studyService.moveModifications(studyUuid, nodeUuid, originNodeUuid, modificationsToCopyUuidList, null, userId); break; default: throw new StudyException(Type.UNKNOWN_ACTION_TYPE); @@ -1146,11 +1143,10 @@ public ResponseEntity getNetworkModifications(@Parameter(description = " @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The network modification was created"), @ApiResponse(responseCode = "404", description = "The study/node is not found")}) public ResponseEntity createNetworkModification(@Parameter(description = "Study UUID") @PathVariable("studyUuid") UUID studyUuid, @Parameter(description = "Node UUID") @PathVariable("nodeUuid") UUID nodeUuid, - @Parameter(description = "Active root network uuid - will apply iteratively modifications for this root network only") @RequestParam(value = "rootNetworkUuid") UUID rootNetworkUuid, @RequestBody String modificationAttributes, @RequestHeader(HEADER_USER_ID) String userId) { studyService.assertCanUpdateModifications(studyUuid, nodeUuid); - studyService.createNetworkModification(studyUuid, modificationAttributes, nodeUuid, rootNetworkUuid, userId); + studyService.createNetworkModification(studyUuid, modificationAttributes, nodeUuid, userId); return ResponseEntity.ok().build(); } @@ -1186,14 +1182,13 @@ public ResponseEntity deleteNetworkModifications(@Parameter(description = public ResponseEntity stashNetworkModifications(@Parameter(description = "Study UUID") @PathVariable("studyUuid") UUID studyUuid, @Parameter(description = "Node UUID") @PathVariable("nodeUuid") UUID nodeUuid, @Parameter(description = "Network modification UUIDs") @RequestParam("uuids") List networkModificationUuids, - @Parameter(description = "active root network uuid - will apply iteratively modifications for this root network only") @RequestParam(value = "rootNetworkUuid") UUID rootNetworkUuid, @Parameter(description = "Stashed Modification") @RequestParam(name = "stashed", required = true) Boolean stashed, @RequestHeader(HEADER_USER_ID) String userId) { studyService.assertCanUpdateModifications(studyUuid, nodeUuid); if (stashed.booleanValue()) { - studyService.stashNetworkModifications(studyUuid, nodeUuid, rootNetworkUuid, networkModificationUuids, userId); + studyService.stashNetworkModifications(studyUuid, nodeUuid, networkModificationUuids, userId); } else { - studyService.restoreNetworkModifications(studyUuid, nodeUuid, rootNetworkUuid, networkModificationUuids, userId); + studyService.restoreNetworkModifications(studyUuid, nodeUuid, networkModificationUuids, userId); } return ResponseEntity.ok().build(); } @@ -1204,11 +1199,10 @@ public ResponseEntity stashNetworkModifications(@Parameter(description = " public ResponseEntity updateNetworkModificationsActivation(@Parameter(description = "Study UUID") @PathVariable("studyUuid") UUID studyUuid, @Parameter(description = "Node UUID") @PathVariable("nodeUuid") UUID nodeUuid, @Parameter(description = "Network modification UUIDs") @RequestParam("uuids") List networkModificationUuids, - @Parameter(description = "active root network uuid - will apply iteratively modifications for this root network only") @RequestParam(value = "rootNetworkUuid") UUID rootNetworkUuid, @Parameter(description = "New activated value") @RequestParam(name = "activated", required = true) Boolean activated, @RequestHeader(HEADER_USER_ID) String userId) { studyService.assertCanUpdateModifications(studyUuid, nodeUuid); - studyService.updateNetworkModificationsActivation(studyUuid, nodeUuid, rootNetworkUuid, networkModificationUuids, userId, activated); + studyService.updateNetworkModificationsActivation(studyUuid, nodeUuid, networkModificationUuids, userId, activated); return ResponseEntity.ok().build(); } diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index a2007779c..96fc1bbe2 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -1296,17 +1296,20 @@ private void removeSecurityAnalysisParameters(@Nullable UUID securityAnalysisPar } } - public void createNetworkModification(UUID studyUuid, String createModificationAttributes, UUID nodeUuid, UUID rootNetworkUuid, String userId) { + public void createNetworkModification(UUID studyUuid, String createModificationAttributes, UUID nodeUuid, String userId) { List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); notificationService.emitStartModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.MODIFICATIONS_CREATING_IN_PROGRESS); try { - RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoService.getRootNetworkNodeInfo(nodeUuid, rootNetworkUuid).orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); - UUID groupUuid = networkModificationTreeService.getModificationGroupUuid(nodeUuid); - String variantId = rootNetworkNodeInfoEntity.getVariantId(); - UUID reportUuid = rootNetworkNodeInfoEntity.getModificationReports().get(nodeUuid); - - Optional networkModificationResult = networkModificationService.createModification(studyUuid, createModificationAttributes, groupUuid, variantId, reportUuid, nodeUuid, rootNetworkUuid); - updateNode(studyUuid, nodeUuid, rootNetworkUuid, networkModificationResult); + rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> { + UUID rootNetworkUuid = rootNetworkEntity.getId(); + RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoService.getRootNetworkNodeInfo(nodeUuid, rootNetworkUuid).orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); + UUID groupUuid = networkModificationTreeService.getModificationGroupUuid(nodeUuid); + String variantId = rootNetworkNodeInfoEntity.getVariantId(); + UUID reportUuid = rootNetworkNodeInfoEntity.getModificationReports().get(nodeUuid); + + Optional networkModificationResult = networkModificationService.createModification(studyUuid, createModificationAttributes, groupUuid, variantId, reportUuid, nodeUuid, rootNetworkUuid); + updateNode(studyUuid, nodeUuid, rootNetworkUuid, networkModificationResult); + }); } finally { notificationService.emitEndModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids); } @@ -1535,7 +1538,7 @@ public void deleteNetworkModifications(UUID studyUuid, UUID nodeUuid, List } @Transactional - public void stashNetworkModifications(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, List modificationsUuids, String userId) { + public void stashNetworkModifications(UUID studyUuid, UUID nodeUuid, List modificationsUuids, String userId) { List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); notificationService.emitStartModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.MODIFICATIONS_STASHING_IN_PROGRESS); try { @@ -1552,7 +1555,7 @@ public void stashNetworkModifications(UUID studyUuid, UUID nodeUuid, UUID rootNe } @Transactional - public void updateNetworkModificationsActivation(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, List modificationsUuids, String userId, boolean activated) { + public void updateNetworkModificationsActivation(UUID studyUuid, UUID nodeUuid, List modificationsUuids, String userId, boolean activated) { List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); notificationService.emitStartModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.MODIFICATIONS_UPDATING_IN_PROGRESS); try { @@ -1569,7 +1572,7 @@ public void updateNetworkModificationsActivation(UUID studyUuid, UUID nodeUuid, } @Transactional - public void restoreNetworkModifications(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, List modificationsUuids, String userId) { + public void restoreNetworkModifications(UUID studyUuid, UUID nodeUuid, List modificationsUuids, String userId) { List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); notificationService.emitStartModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.MODIFICATIONS_RESTORING_IN_PROGRESS); try { @@ -1696,7 +1699,7 @@ public StudyIndexationStatus getStudyIndexationStatus(UUID studyUuid, UUID rootN } @Transactional - public void moveModifications(UUID studyUuid, UUID targetNodeUuid, UUID originNodeUuid, UUID rootNetworkUuid, List modificationUuidList, UUID beforeUuid, String userId) { + public void moveModifications(UUID studyUuid, UUID targetNodeUuid, UUID originNodeUuid, List modificationUuidList, UUID beforeUuid, String userId) { if (originNodeUuid == null) { throw new StudyException(MISSING_PARAMETER, "The parameter 'originNodeUuid' must be defined when moving modifications"); } @@ -1719,20 +1722,26 @@ public void moveModifications(UUID studyUuid, UUID targetNodeUuid, UUID originNo checkStudyContainsNode(studyUuid, targetNodeUuid); UUID originGroupUuid = networkModificationTreeService.getModificationGroupUuid(originNodeUuid); NetworkModificationNodeInfoEntity networkModificationNodeInfoEntity = networkModificationTreeService.getNetworkModificationNodeInfoEntity(targetNodeUuid); - RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoService.getRootNetworkNodeInfo(targetNodeUuid, rootNetworkUuid).orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); - UUID networkUuid = rootNetworkService.getNetworkUuid(rootNetworkUuid); - Optional networkModificationResult = networkModificationService.moveModifications(originGroupUuid, modificationUuidList, beforeUuid, networkUuid, networkModificationNodeInfoEntity, rootNetworkNodeInfoEntity, buildTargetNode); - if (!targetNodeBelongsToSourceNodeSubTree) { - // invalidate the whole subtree except maybe the target node itself (depends if we have built this node during the move) - networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, targetNodeUuid, rootNetworkUuid, modificationResult)); - updateStatuses(studyUuid, targetNodeUuid, buildTargetNode, true, true); - } - if (moveBetweenNodes) { - // invalidate the whole subtree including the source node - networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, originNodeUuid, rootNetworkUuid, modificationResult)); - updateStatuses(studyUuid, originNodeUuid, false, true, true); - } + rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> { + UUID rootNetworkUuid = rootNetworkEntity.getId(); + RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoService.getRootNetworkNodeInfo(targetNodeUuid, rootNetworkUuid).orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); + UUID networkUuid = rootNetworkService.getNetworkUuid(rootNetworkUuid); + Optional networkModificationResult = networkModificationService.moveModifications(originGroupUuid, modificationUuidList, beforeUuid, networkUuid, networkModificationNodeInfoEntity, rootNetworkNodeInfoEntity, buildTargetNode); + if (!targetNodeBelongsToSourceNodeSubTree) { + // invalidate the whole subtree except maybe the target node itself (depends if we have built this node during the move) + networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, targetNodeUuid, rootNetworkUuid, modificationResult)); + //TODO : should take rootnetworkuuid as param + updateStatuses(studyUuid, targetNodeUuid, buildTargetNode, true, true); + } + if (moveBetweenNodes) { + // invalidate the whole subtree including the source node + networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, originNodeUuid, rootNetworkUuid, modificationResult)); + //TODO : should take rootnetworkuuid as param + updateStatuses(studyUuid, originNodeUuid, false, true, true); + } + }); } finally { + //TODO : should take rootnetworkuuid as param notificationService.emitEndModificationEquipmentNotification(studyUuid, targetNodeUuid, childrenUuids); if (moveBetweenNodes) { notificationService.emitEndModificationEquipmentNotification(studyUuid, originNodeUuid, originNodeChildrenUuids); @@ -1742,17 +1751,21 @@ public void moveModifications(UUID studyUuid, UUID targetNodeUuid, UUID originNo } @Transactional - public void createModifications(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, List modificationUuidList, String userId, StudyConstants.ModificationsActionType action) { + public void createModifications(UUID studyUuid, UUID nodeUuid, List modificationUuidList, String userId, StudyConstants.ModificationsActionType action) { List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); notificationService.emitStartModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.MODIFICATIONS_UPDATING_IN_PROGRESS); try { checkStudyContainsNode(studyUuid, nodeUuid); NetworkModificationNodeInfoEntity networkModificationNodeInfoEntity = networkModificationTreeService.getNetworkModificationNodeInfoEntity(nodeUuid); - RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoService.getRootNetworkNodeInfo(nodeUuid, rootNetworkUuid).orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); - UUID networkUuid = rootNetworkService.getNetworkUuid(rootNetworkUuid); - Optional networkModificationResult = networkModificationService.createModifications(modificationUuidList, networkUuid, networkModificationNodeInfoEntity, rootNetworkNodeInfoEntity, action); - // invalidate the whole subtree except the target node (we have built this node during the duplication) - networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, nodeUuid, rootNetworkUuid, modificationResult)); + rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> { + UUID rootNetworkUuid = rootNetworkEntity.getId(); + RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoService.getRootNetworkNodeInfo(nodeUuid, rootNetworkUuid).orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); + UUID networkUuid = rootNetworkService.getNetworkUuid(rootNetworkUuid); + Optional networkModificationResult = networkModificationService.createModifications(modificationUuidList, networkUuid, networkModificationNodeInfoEntity, rootNetworkNodeInfoEntity, action); + // invalidate the whole subtree except the target node (we have built this node during the duplication) + networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, nodeUuid, rootNetworkUuid, modificationResult)); + }); + //TODO: NOT WORKING WELL, NOTIF HAS TO TARGET ROOT NETWORK UUID updateStatuses(studyUuid, nodeUuid, true, true, true); } finally { notificationService.emitEndModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids); diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java index b327401a8..ab1016f35 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java @@ -145,7 +145,6 @@ class NetworkModificationTest { private static final long TIMEOUT = 1000; private static final String URI_NETWORK_MODIF = "/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications"; - private static final String URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID = "/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications?rootNetworkUuid={rootNetworkUuid}"; private static final String URI_NETWORK_MODIF_WITH_ID = "/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications/{uuid}"; private static final NetworkModificationResult DEFAULT_BUILD_RESULT = createModificationResultWithElementImpact(SimpleImpactType.CREATION, IdentifiableType.LINE, "lineId", Set.of("s1", "s2")).get(); @@ -214,9 +213,6 @@ class NetworkModificationTest { @Autowired private StudyService studyService; - @Autowired - private StudyTestUtils studyTestUtils; - //output destinations private static final String STUDY_UPDATE_DESTINATION = "study.update"; private static final String ELEMENT_UPDATE_DESTINATION = "element.update"; @@ -555,7 +551,7 @@ void testBuild() throws Exception { @Test void testLocalBuildValue() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyEntity.getId()); + UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); String userId = "userId"; @@ -585,7 +581,7 @@ void testLocalBuildValue() throws Exception { // Build first node with errors networkModificationResult.get().setApplicationStatus(NetworkModificationResult.ApplicationStatus.WITH_ERRORS); UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -597,13 +593,13 @@ void testLocalBuildValue() throws Exception { checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, firstRootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, rootNetworkUuid).getGlobalBuildStatus()); wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING); // Build second node is OK networkModificationResult.get().setApplicationStatus(NetworkModificationResult.ApplicationStatus.ALL_OK); stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -615,12 +611,12 @@ void testLocalBuildValue() throws Exception { checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNode2Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); - assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, firstRootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, rootNetworkUuid).getGlobalBuildStatus()); wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING); //Build modification node 2, local status should be BUILT and computed one should be BUILT_WITH_ERRORS - assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, firstRootNetworkUuid).getLocalBuildStatus()); - assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, firstRootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, rootNetworkUuid).getLocalBuildStatus()); + assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, rootNetworkUuid).getGlobalBuildStatus()); } @Test @@ -631,7 +627,7 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyEntity.getId()); + UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, @@ -651,14 +647,14 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception String bodyJson = mapper.writeValueAsString(body); // update switch on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // update switch on first modification node UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -679,7 +675,7 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception assertThat(csbiListResult.get(0), createMatcherCreatedStudyBasicInfos(studyNameUserIdUuid, "UCTE")); // update switch on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -702,7 +698,7 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception Optional networkModificationResult = createModificationResultWithElementImpact(SimpleImpactType.MODIFICATION, IdentifiableType.SWITCH, "switchId", Set.of("s1", "s2", "s3")); stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -719,10 +715,10 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception assertTrue(requests.stream().anyMatch(r -> r.getPath().matches("/v1/reports"))); // modificationNode2 is still built - assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode1Uuid, firstRootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode1Uuid, rootNetworkUuid).getGlobalBuildStatus()); // modificationNode2 is now invalid - assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, firstRootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, rootNetworkUuid).getGlobalBuildStatus()); } @Test @@ -733,7 +729,6 @@ void testNetworkModificationEquipment() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node 1", userId); UUID modificationNodeUuid = modificationNode.getId(); @@ -748,14 +743,14 @@ void testNetworkModificationEquipment() throws Exception { String bodyJson = mapper.writeValueAsString(body); //update equipment on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); //update equipment UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -775,7 +770,7 @@ void testNetworkModificationEquipment() throws Exception { assertThat(csbiListResponse.get(0), createMatcherCreatedStudyBasicInfos(studyNameUserIdUuid, "UCTE")); // update equipment on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid2, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid2) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -793,7 +788,6 @@ void testCreateGenerator() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -819,14 +813,14 @@ void testCreateGenerator() throws Exception { String bodyJsonCreate = mapper.writeValueAsString(body); // create generator on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(bodyJsonCreate).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // create generator on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -838,7 +832,7 @@ void testCreateGenerator() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, bodyJsonCreate, NETWORK_UUID_STRING, VARIANT_ID); // create generator on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(bodyJsonCreate).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -875,7 +869,7 @@ void testCreateGenerator() throws Exception { body.replace("maxActivePower", "200.0"); String bodyJsonCreateBis = mapper.writeValueAsString(body); when(rootNetworkNodeInfoRepository.existsByStudyUuidAndBuildStatus(studyNameUserIdUuid, BuildStatus.BUILDING)).thenReturn(true); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreateBis).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); @@ -886,7 +880,6 @@ void testCreateShuntsCompensator() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -895,14 +888,14 @@ void testCreateShuntsCompensator() throws Exception { String createShuntCompensatorAttributes = "{\"type\":\"" + ModificationType.SHUNT_COMPENSATOR_CREATION + "\",\"shuntCompensatorId\":\"shuntCompensatorId1\",\"shuntCompensatorName\":\"shuntCompensatorName1\",\"voltageLevelId\":\"idVL1\",\"busOrBusbarSectionId\":\"idBus1\"}"; // create shuntCompensator on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(createShuntCompensatorAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // create shuntCompensator on modification node child of root node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createShuntCompensatorAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -930,7 +923,7 @@ void testCreateShuntsCompensator() throws Exception { when(rootNetworkNodeInfoRepository.existsByStudyUuidAndBuildStatus(studyNameUserIdUuid, BuildStatus.BUILDING)).thenReturn(true); // create shunt compensator on building node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createShuntCompensatorAttributes2).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); @@ -941,7 +934,6 @@ void testCreateLine() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -959,14 +951,14 @@ void testCreateLine() throws Exception { + "\"voltageLevelId2\":\"idVL2\"," + "\"busOrBusbarSectionId2\":\"idBus2\"}"; // create line on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(createLineAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // create line on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createLineAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -978,7 +970,7 @@ void testCreateLine() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createLineAttributes, NETWORK_UUID_STRING, VARIANT_ID); // create line on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(createLineAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1020,7 +1012,7 @@ void testCreateLine() throws Exception { rootNetworkNodeInfo1Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILDING)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo1Entity); // create line on building node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createLineAttributes2).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); @@ -1031,7 +1023,6 @@ void testCreateTwoWindingsTransformer() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -1043,14 +1034,14 @@ void testCreateTwoWindingsTransformer() throws Exception { String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; // create 2WT on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // create 2WT on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1062,7 +1053,7 @@ void testCreateTwoWindingsTransformer() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING, VARIANT_ID); // create 2WT on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1092,7 +1083,7 @@ void testCreateTwoWindingsTransformer() throws Exception { rootNetworkNodeInfo1Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILDING)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo1Entity); // create Two Windings Transformer on building node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createTwoWindingsTransformerAttributes2).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); @@ -1106,7 +1097,6 @@ void deleteModificationRequest() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); UUID rootNodeUuid = getRootNode(studyUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyUuid, rootNodeUuid, VARIANT_ID, "node 1", userId); createNetworkModificationNode(studyUuid, rootNodeUuid, VARIANT_ID_2, "node 2", userId); @@ -1153,7 +1143,6 @@ void testUpdateLines() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -1170,13 +1159,13 @@ void testUpdateLines() throws Exception { // change line status on root node (not allowed) UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(bodyJsonCreate1).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // lockout line - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate1).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1190,7 +1179,7 @@ void testUpdateLines() throws Exception { bodyLineInfos.put("equipmentId", "lineFailedId"); String bodyJsonCreate2 = mapper.writeValueAsString(bodyLineInfos); stubPostId = wireMockUtils.stubNetworkModificationPostWithError(bodyJsonCreate2); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate2).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isBadRequest()); @@ -1203,7 +1192,7 @@ void testUpdateLines() throws Exception { bodyLineInfos.put("action", "trip"); String bodyJsonCreate3 = mapper.writeValueAsString(bodyLineInfos); stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate3).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1217,7 +1206,7 @@ void testUpdateLines() throws Exception { bodyLineInfos.put("equipmentId", "lineFailedId"); String bodyJsonCreate4 = mapper.writeValueAsString(bodyLineInfos); stubPostId = wireMockUtils.stubNetworkModificationPostWithError(bodyJsonCreate4); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate4).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isBadRequest()); @@ -1230,7 +1219,7 @@ void testUpdateLines() throws Exception { bodyLineInfos.put("action", "energiseEndOne"); String bodyJsonCreate5 = mapper.writeValueAsString(bodyLineInfos); stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate5).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1244,7 +1233,7 @@ void testUpdateLines() throws Exception { bodyLineInfos.put("equipmentId", "lineFailedId"); String bodyJsonCreate6 = mapper.writeValueAsString(bodyLineInfos); stubPostId = wireMockUtils.stubNetworkModificationPostWithError(bodyJsonCreate6); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate6).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isBadRequest()); @@ -1257,7 +1246,7 @@ void testUpdateLines() throws Exception { bodyLineInfos.put("action", "switchOn"); String bodyJsonCreate7 = mapper.writeValueAsString(bodyLineInfos); stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate7).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1271,7 +1260,7 @@ void testUpdateLines() throws Exception { bodyLineInfos.put("equipmentId", "lineFailedId"); String bodyJsonCreate8 = mapper.writeValueAsString(bodyLineInfos); stubPostId = wireMockUtils.stubNetworkModificationPostWithError(bodyJsonCreate8); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate8).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isBadRequest()); @@ -1282,7 +1271,7 @@ void testUpdateLines() throws Exception { // switch on line on second modification node String bodyJsonCreate9 = bodyJsonCreate7; stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(bodyJsonCreate9).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1299,7 +1288,6 @@ void testCreateLoad() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -1314,14 +1302,14 @@ void testCreateLoad() throws Exception { String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; // create load on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(createLoadAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // create load on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createLoadAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1333,7 +1321,7 @@ void testCreateLoad() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID); // create load on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(createLoadAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1364,7 +1352,7 @@ void testCreateLoad() throws Exception { rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo3Entity); // create load on building node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode3Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode3Uuid) .content(createLoadAttributes2).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); @@ -1375,7 +1363,6 @@ void testModifyLoad() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -1387,14 +1374,14 @@ void testModifyLoad() throws Exception { String loadModificationAttributes = "{\"type\":\"" + ModificationType.LOAD_MODIFICATION + "\",\"equipmentId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"AUXILIARY\",\"activePower\":\"100.0\"}"; // modify load on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(loadModificationAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // modify load on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(loadModificationAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1406,7 +1393,7 @@ void testModifyLoad() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, loadModificationAttributes, NETWORK_UUID_STRING, VARIANT_ID); // modify load on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid2, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid2) .content(loadModificationAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1436,7 +1423,6 @@ void testModifyEquipment() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); UUID modificationNodeUuid = modificationNode.getId(); @@ -1445,14 +1431,14 @@ void testModifyEquipment() throws Exception { // modify generator on root node (not allowed) String equipmentModificationAttribute = "{\"type\":\"" + ModificationType.GENERATOR_MODIFICATION + "\",\"equipmentId\":\"equipmentId\"}"; - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(equipmentModificationAttribute).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // modify generator on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(equipmentModificationAttribute).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1464,7 +1450,7 @@ void testModifyEquipment() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, equipmentModificationAttribute, NETWORK_UUID_STRING, VARIANT_ID); // modify generator on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid2, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid2) .content(equipmentModificationAttribute).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1494,7 +1480,6 @@ void testCreateSubstation() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -1506,14 +1491,14 @@ void testCreateSubstation() throws Exception { String createSubstationAttributes = "{\"type\":\"" + ModificationType.SUBSTATION_CREATION + "\",\"substationId\":\"substationId1\",\"substationName\":\"substationName1\",\"country\":\"AD\"}"; // create substation on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(createSubstationAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // create substation on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createSubstationAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1525,7 +1510,7 @@ void testCreateSubstation() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createSubstationAttributes, NETWORK_UUID_STRING, VARIANT_ID); // create substation on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(createSubstationAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1555,7 +1540,7 @@ void testCreateSubstation() throws Exception { rootNetworkNodeInfo1Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILDING)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo1Entity); // create substation on building node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createSubstationAttributes2).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); @@ -1566,7 +1551,6 @@ void testCreateVoltageLevel() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node 1", userId); UUID modificationNode1Uuid = modificationNode1.getId(); @@ -1578,14 +1562,14 @@ void testCreateVoltageLevel() throws Exception { + ",\"nominalVoltage\":\"379.1\", \"substationId\":\"s1\"}"; // create voltage level on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(createVoltageLevelAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // create voltage level UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createVoltageLevelAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1597,7 +1581,7 @@ void testCreateVoltageLevel() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createVoltageLevelAttributes, NETWORK_UUID_STRING, VARIANT_ID); // create voltage level on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(createVoltageLevelAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1629,7 +1613,7 @@ void testCreateVoltageLevel() throws Exception { rootNetworkNodeInfo1Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILDING)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo1Entity); // create voltage level on building node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createVoltageLevelAttributes2).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); @@ -1640,7 +1624,6 @@ void testLineSplitWithVoltageLevel() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); @@ -1659,7 +1642,7 @@ void testLineSplitWithVoltageLevel() throws Exception { String lineSplitWoVLasJSON = mapper.writeValueAsString(lineSplitWoVL); UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(lineSplitWoVLasJSON).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1684,7 +1667,7 @@ void testLineSplitWithVoltageLevel() throws Exception { String badBody = "{\"type\":\"" + ModificationType.LINE_SPLIT_WITH_VOLTAGE_LEVEL + "\",\"bogus\":\"bogus\"}"; stubPostId = wireMockUtils.stubNetworkModificationPostWithBodyAndError(badBody); stubPutId = wireMockUtils.stubNetworkModificationPutWithBodyAndError(MODIFICATION_UUID, badBody); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(badBody).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpectAll( @@ -1709,7 +1692,6 @@ void testLineAttachToVoltageLevel() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); @@ -1721,7 +1703,7 @@ void testLineAttachToVoltageLevel() throws Exception { createVoltageLevelAttributes + ",\"attachmentLine\":" + createLineAttributes + "}"; UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(createLineAttachToVoltageLevelAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1749,14 +1731,13 @@ void testLinesAttachToSplitLines() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); String createLinesAttachToSplitLinesAttributes = "{\"type\":\"" + ModificationType.LINES_ATTACH_TO_SPLIT_LINES + "\",\"lineToAttachTo1Id\":\"line1\",\"lineToAttachTo2Id\":\"line2\",\"attachedLineId\":\"line3\",\"voltageLevelId\":\"vl1\",\"bbsBusId\":\"v1bbs\",\"replacingLine1Id\":\"replacingLine1Id\",\"replacingLine1Name\":\"replacingLine1Name\",\"replacingLine2Id\":\"replacingLine2Id\",\"replacingLine2Name\":\"replacingLine2Name\"}"; UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(createLinesAttachToSplitLinesAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1781,7 +1762,7 @@ void testLinesAttachToSplitLines() throws Exception { String badBody = "{\"type\":\"" + ModificationType.LINES_ATTACH_TO_SPLIT_LINES + "\",\"bogus\":\"bogus\"}"; stubPostId = wireMockUtils.stubNetworkModificationPostWithBodyAndError(badBody); stubPutId = wireMockUtils.stubNetworkModificationPutWithBodyAndError(MODIFICATION_UUID, badBody); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(badBody).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isBadRequest()); @@ -1806,13 +1787,12 @@ void testScaling(ModificationType scalingType) throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(requestBody).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1836,7 +1816,7 @@ void testScaling(ModificationType scalingType) throws Exception { // test with errors stubPostId = wireMockUtils.stubNetworkModificationPostWithBodyAndError(requestBody); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(requestBody).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().is4xxClientError()); @@ -1859,7 +1839,6 @@ void testDeleteVoltageLevelOnline() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); @@ -1867,7 +1846,7 @@ void testDeleteVoltageLevelOnline() throws Exception { String createDeleteVoltageLevelOnlineAttributes = "{\"type\":\"" + ModificationType.DELETE_VOLTAGE_LEVEL_ON_LINE + "\",\"lineToAttachTo1Id\":\"line1\",\"lineToAttachTo2Id\":\"line2\",\"replacingLine1Id\":\"replacingLine1Id\",\"replacingLine1Name\":\"replacingLine1Name\"}"; UUID stubIdPost = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(createDeleteVoltageLevelOnlineAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1890,7 +1869,7 @@ void testDeleteVoltageLevelOnline() throws Exception { String badBody = "{\"type\":\"" + ModificationType.DELETE_VOLTAGE_LEVEL_ON_LINE + "\",\"bogus\":\"bogus\"}"; UUID stubIdPostErr = wireMockUtils.stubNetworkModificationPostWithBodyAndError(badBody); UUID stubIdPutErr = wireMockUtils.stubNetworkModificationPutWithBodyAndError(MODIFICATION_UUID, badBody); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid).header(USER_ID_HEADER, userId) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid).header(USER_ID_HEADER, userId) .content(badBody).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isBadRequest()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); @@ -1911,14 +1890,13 @@ void testDeleteAttachingline() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); String createDeleteAttachingLineAttributes = "{\"type\":\"" + ModificationType.DELETE_ATTACHING_LINE + "\",\"lineToAttachTo1Id\":\"line1\",\"lineToAttachTo2Id\":\"line2\",\"attachedLineId\":\"line3\",\"replacingLine1Id\":\"replacingLine1Id\",\"replacingLine1Name\":\"replacingLine1Name\"}"; UUID stubIdPost = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(createDeleteAttachingLineAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -1941,7 +1919,7 @@ void testDeleteAttachingline() throws Exception { String badBody = "{\"type\":\"" + ModificationType.DELETE_ATTACHING_LINE + "\",\"bogus\":\"bogus\"}"; UUID stubIdPostErr = wireMockUtils.stubNetworkModificationPostWithBodyAndError(badBody); UUID stubIdPutErr = wireMockUtils.stubNetworkModificationPutWithBodyAndError(MODIFICATION_UUID, badBody); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(badBody).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isBadRequest()); @@ -1963,7 +1941,6 @@ void testReorderModification() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node", userId); @@ -1979,8 +1956,8 @@ void testReorderModification() throws Exception { .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); // switch the 2 modifications order (modification1 is set at the end, after modification2) - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?rootNetworkUuid={rootNetworkUuid}", - studyNameUserIdUuid, modificationNodeUuid, modification1, firstRootNetworkUuid).header(USER_ID_HEADER, "userId")) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}", + studyNameUserIdUuid, modificationNodeUuid, modification1).header(USER_ID_HEADER, "userId")) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); @@ -2002,8 +1979,8 @@ void testReorderModification() throws Exception { expectedBody); // switch back the 2 modifications order (modification1 is set before modification2) - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?beforeUuid={modificationID2}&rootNetworkUuid={rootNetworkUuid}", - studyNameUserIdUuid, modificationNodeUuid, modification1, modification2, firstRootNetworkUuid).header(USER_ID_HEADER, "userId")) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?beforeUuid={modificationID2}", + studyNameUserIdUuid, modificationNodeUuid, modification1, modification2).header(USER_ID_HEADER, "userId")) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); @@ -2028,7 +2005,6 @@ void testReorderModificationErrorCase() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node", userId); @@ -2037,17 +2013,16 @@ void testReorderModificationErrorCase() throws Exception { UUID modification1 = UUID.randomUUID(); UUID modification2 = UUID.randomUUID(); UUID studyNameUserIdUuid1 = UUID.randomUUID(); - UUID rootNetworkUuid1 = UUID.randomUUID(); UUID nodeIdUuid1 = UUID.randomUUID(); - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?beforeUuid={modificationID2}&rootNetworkUuid={rootNetworkUuid}", - studyNameUserIdUuid, nodeIdUuid1, modification1, modification2, firstRootNetworkUuid).header(USER_ID_HEADER, "userId")) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?beforeUuid={modificationID2}", + studyNameUserIdUuid, nodeIdUuid1, modification1, modification2).header(USER_ID_HEADER, "userId")) .andExpect(status().isNotFound()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, nodeIdUuid1); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, nodeIdUuid1); - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?beforeUuid={modificationID2}&rootNetworkUuid={rootNetworkUuid}", - studyNameUserIdUuid1, modificationNodeUuid, modification1, modification2, rootNetworkUuid1).header(USER_ID_HEADER, "userId")) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?beforeUuid={modificationID2}", + studyNameUserIdUuid1, modificationNodeUuid, modification1, modification2).header(USER_ID_HEADER, "userId")) .andExpect(status().isForbidden()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid1, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid1, modificationNodeUuid); @@ -2058,7 +2033,6 @@ void testDuplicateModification() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); UUID rootNodeUuid = getRootNode(studyUuid).getId(); NetworkModificationNode node1 = createNetworkModificationNode(studyUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "New node 1", "userId"); @@ -2074,8 +2048,8 @@ void testDuplicateModification() throws Exception { .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); // duplicate 2 modifications in node1 - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY&rootNetworkUuid={rootNetworkUuid}", - studyUuid, nodeUuid1, firstRootNetworkUuid) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY", + studyUuid, nodeUuid1) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) @@ -2108,8 +2082,8 @@ void testDuplicateModification() throws Exception { .withBody(mapper.writeValueAsString(Optional.of(NetworkModificationResult.builder().build()))) .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY&rootNetworkUuid={rootNetworkUuid}", - studyUuid, nodeUuid1, firstRootNetworkUuid) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY", + studyUuid, nodeUuid1) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) @@ -2139,7 +2113,6 @@ void testDuplicateModification() throws Exception { void testDuplicateModificationErrorCase() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); UUID rootNodeUuid = getRootNode(studyUuid).getId(); createNetworkModificationNode(studyUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "New node 1", "userId"); UUID modification1 = UUID.randomUUID(); @@ -2147,16 +2120,16 @@ void testDuplicateModificationErrorCase() throws Exception { String modificationUuidListBody = mapper.writeValueAsString(Arrays.asList(modification1, modification2)); // Random/bad studyId error case - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY&rootNetworkUuid={rootNetworkUuid}", - UUID.randomUUID(), rootNodeUuid, firstRootNetworkUuid) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY", + UUID.randomUUID(), rootNodeUuid) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) .andExpect(status().isNotFound()); // Random/bad nodeId error case - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY&rootNetworkUuid={rootNetworkUuid}", - studyUuid, UUID.randomUUID(), firstRootNetworkUuid) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY", + studyUuid, UUID.randomUUID()) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) @@ -2169,7 +2142,6 @@ void testCutAndPasteModification() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); UUID rootNodeUuid = getRootNode(studyUuid).getId(); NetworkModificationNode node1 = createNetworkModificationNode(studyUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "New node 1", userId); @@ -2188,8 +2160,8 @@ void testCutAndPasteModification() throws Exception { .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); // move 2 modifications within node 1 - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?originNodeUuid={originNodeUuid}&action=MOVE&rootNetworkUuid={rootNetworkUuid}", - studyUuid, nodeUuid1, nodeUuid1, firstRootNetworkUuid) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?originNodeUuid={originNodeUuid}&action=MOVE", + studyUuid, nodeUuid1, nodeUuid1) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) @@ -2213,8 +2185,8 @@ void testCutAndPasteModification() throws Exception { expectedBody); // move 2 modifications from node1 to node2 - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?originNodeUuid={originNodeUuid}&action=MOVE&rootNetworkUuid={rootNetworkUuid}", - studyUuid, nodeUuid2, nodeUuid1, firstRootNetworkUuid) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?originNodeUuid={originNodeUuid}&action=MOVE", + studyUuid, nodeUuid2, nodeUuid1) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) @@ -2244,8 +2216,8 @@ void testCutAndPasteModification() throws Exception { expectedBody); // move modification without defining originNodeUuid - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=MOVE&rootNetworkUuid={rootNetworkUuid}", - studyUuid, nodeUuid1, firstRootNetworkUuid) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=MOVE", + studyUuid, nodeUuid1) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) @@ -2265,16 +2237,16 @@ void testCutAndPasteModificationErrorCase() throws Exception { String modificationUuidListBody = mapper.writeValueAsString(Arrays.asList(modification1, modification2)); // Random/bad studyId error case - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?originNodeUuid={originNodeUuid}&action=MOVE&rootNetworkUuid={rootNetworkUuid}", - UUID.randomUUID(), rootNodeUuid, UUID.randomUUID(), UUID.randomUUID()) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?originNodeUuid={originNodeUuid}&action=MOVE", + UUID.randomUUID(), rootNodeUuid, UUID.randomUUID()) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) .andExpect(status().isNotFound()); // Random/bad nodeId error case - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?originNodeUuid={originNodeUuid}&action=MOVE&rootNetworkUuid={rootNetworkUuid}", - studyUuid, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()) + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?originNodeUuid={originNodeUuid}&action=MOVE", + studyUuid, UUID.randomUUID(), UUID.randomUUID()) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) .header(USER_ID_HEADER, "userId")) @@ -2286,7 +2258,6 @@ void testDeleteEquipment() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -2303,14 +2274,14 @@ void testDeleteEquipment() throws Exception { String bodyJson = mapper.writeValueAsString(body); // delete equipment on root node (not allowed) - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, rootNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isForbidden()); // delete equipment on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2322,7 +2293,7 @@ void testDeleteEquipment() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, bodyJson, NETWORK_UUID_STRING, VARIANT_ID); // delete equipment on second modification node - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2350,8 +2321,8 @@ void testDeleteEquipment() throws Exception { void testNodesInvalidation(final MockWebServer server) throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); + UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", BuildStatus.BUILT, userId); UUID modificationNode1Uuid = modificationNode1.getId(); @@ -2410,7 +2381,7 @@ void testNodesInvalidation(final MockWebServer server) throws Exception { Map createLoadInfos = Map.of("type", ModificationType.LOAD_CREATION, "equipmentId", "loadId"); String jsonCreateLoadInfos = mapper.writeValueAsString(createLoadInfos); stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode2Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2419,7 +2390,7 @@ void testNodesInvalidation(final MockWebServer server) throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode3Uuid, firstRootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode3Uuid, rootNetworkUuid).getGlobalBuildStatus()); wireMockUtils.verifyNetworkModificationPost(stubUuid, jsonCreateLoadInfos, NETWORK_UUID_STRING); requests = TestUtils.getRequestsWithBodyDone(1, server); @@ -2431,7 +2402,6 @@ void testRemoveLoadFlowComputationReport(final MockWebServer server) throws Exce String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", BuildStatus.BUILT, userId); UUID modificationNode1Uuid = modificationNode1.getId(); @@ -2469,7 +2439,7 @@ void testRemoveLoadFlowComputationReport(final MockWebServer server) throws Exce // add this modification to the node => invalidate the LF UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNode1Uuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2493,7 +2463,7 @@ void testRemoveLoadFlowComputationReport(final MockWebServer server) throws Exce @Test void testUpdateOfBuildStatus() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyEntity.getId()); + UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); String userId = "userId"; @@ -2506,7 +2476,7 @@ void testUpdateOfBuildStatus() throws Exception { // Create network modification on NOT_BUILT modification node UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2515,7 +2485,7 @@ void testUpdateOfBuildStatus() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, firstRootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, rootNetworkUuid).getGlobalBuildStatus()); wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING, VARIANT_ID); // Mark the node status as built @@ -2527,7 +2497,7 @@ void testUpdateOfBuildStatus() throws Exception { Optional networkModificationResult = createModificationResultWithElementImpact(SimpleImpactType.CREATION, IdentifiableType.LOAD, "loadId", Set.of("s1")); stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2538,13 +2508,13 @@ void testUpdateOfBuildStatus() throws Exception { checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, firstRootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, rootNetworkUuid).getGlobalBuildStatus()); wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING, VARIANT_ID); // Built with warnings networkModificationResult.get().setApplicationStatus(NetworkModificationResult.ApplicationStatus.WITH_WARNINGS); stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2555,13 +2525,13 @@ void testUpdateOfBuildStatus() throws Exception { checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - assertEquals(BuildStatus.BUILT_WITH_WARNING, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, firstRootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.BUILT_WITH_WARNING, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, rootNetworkUuid).getGlobalBuildStatus()); wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING); // Built with errors networkModificationResult.get().setApplicationStatus(NetworkModificationResult.ApplicationStatus.WITH_ERRORS); stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2572,7 +2542,7 @@ void testUpdateOfBuildStatus() throws Exception { checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, firstRootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, rootNetworkUuid).getGlobalBuildStatus()); wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING); } @@ -2898,7 +2868,6 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU void testCreateModificationWithErrors() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); String userId = "userId"; NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, @@ -2910,7 +2879,7 @@ void testCreateModificationWithErrors() throws Exception { // Create network modification on first modification node UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -2924,7 +2893,7 @@ void testCreateModificationWithErrors() throws Exception { // String message error String contentErrorMessage = "Internal Server Error"; stubId = wireMockUtils.stubNetworkModificationPostWithError(jsonCreateLoadInfos); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpectAll(status().isBadRequest(), content().string(contentErrorMessage)); @@ -2934,7 +2903,7 @@ void testCreateModificationWithErrors() throws Exception { // Json message error stubId = wireMockUtils.stubNetworkModificationPostWithError(jsonCreateLoadInfos, String.format("{\"message\" : \"%s\"}", contentErrorMessage)); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpectAll(status().isBadRequest(), content().string(contentErrorMessage)); @@ -2945,7 +2914,7 @@ void testCreateModificationWithErrors() throws Exception { // Bad json message error contentErrorMessage = String.format("{\"foo\" : \"%s\"}", contentErrorMessage); stubId = wireMockUtils.stubNetworkModificationPostWithError(jsonCreateLoadInfos, contentErrorMessage); - mockMvc.perform(post(URI_NETWORK_MODIF_WITH_ROOT_NETWORK_UUID, studyNameUserIdUuid, modificationNodeUuid, firstRootNetworkUuid) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpectAll(status().isBadRequest(), content().string(contentErrorMessage)); diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationUnitTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationUnitTest.java index 141340813..6b3e40533 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationUnitTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationUnitTest.java @@ -182,8 +182,7 @@ void deactivateNetworkModificationTest() { } private void updateNetworkModificationActivationStatus(List networkModificationUuids, UUID nodeWithModification, List childrenNodes, List nodesToUnbuild, boolean activated) { - UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); - studyController.updateNetworkModificationsActivation(studyUuid, node1Uuid, networkModificationUuids, firstRootNetworkUuid, activated, "userId"); + studyController.updateNetworkModificationsActivation(studyUuid, node1Uuid, networkModificationUuids, activated, "userId"); checkModificationUpdatedMessageReceived(studyUuid, nodeWithModification, childrenNodes, NotificationService.MODIFICATIONS_UPDATING_IN_PROGRESS); checkUpdateBuildStateMessageReceived(studyUuid, nodesToUnbuild); From 52128449a6500679ddaceba98663bbd917a1f178 Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Tue, 17 Dec 2024 11:38:58 +0100 Subject: [PATCH 03/17] fix: status changes, modifications and notifications are now made with root network uuids Signed-off-by: LE SAULNIER Kevin --- .../notification/NotificationService.java | 22 +++-- .../study/server/service/ConsumerService.java | 14 +-- .../NetworkModificationTreeService.java | 6 +- .../study/server/service/StudyService.java | 92 +++++++++---------- .../service/VoltageInitResultConsumer.java | 2 +- .../StudyServiceDynamicSimulationTest.java | 2 +- 6 files changed, 73 insertions(+), 65 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/notification/NotificationService.java b/src/main/java/org/gridsuite/study/server/notification/NotificationService.java index a16191267..4eb906832 100644 --- a/src/main/java/org/gridsuite/study/server/notification/NotificationService.java +++ b/src/main/java/org/gridsuite/study/server/notification/NotificationService.java @@ -36,6 +36,7 @@ public class NotificationService { public static final String HEADER_ERROR = "error"; public static final String HEADER_NODE = "node"; + public static final String HEADER_ROOT_NETWORK = "rootNetwork"; public static final String HEADER_NODES = "nodes"; public static final String HEADER_STUDY_UUID = "studyUuid"; public static final String HEADER_UPDATE_TYPE = "updateType"; @@ -161,10 +162,11 @@ public void emitStudyNetworkRecreationDone(UUID studyUuid, String userId) { } @PostCompletion - public void emitStudyChanged(UUID studyUuid, UUID nodeUuid, String updateType) { + public void emitStudyChanged(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String updateType) { sendUpdateMessage(MessageBuilder.withPayload("") .setHeader(HEADER_STUDY_UUID, studyUuid) .setHeader(HEADER_NODE, nodeUuid) + .setHeader(HEADER_ROOT_NETWORK, rootNetworkUuid) .setHeader(HEADER_UPDATE_TYPE, updateType) .build()); } @@ -191,10 +193,11 @@ public void emitStudyCreationError(UUID studyUuid, String userId, String errorMe } @PostCompletion - public void emitStudyError(UUID studyUuid, UUID nodeUuid, String updateType, String errorMessage, String userId) { + public void emitStudyError(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String updateType, String errorMessage, String userId) { sendUpdateMessage(MessageBuilder.withPayload("") .setHeader(HEADER_STUDY_UUID, studyUuid) .setHeader(HEADER_NODE, nodeUuid) + .setHeader(HEADER_ROOT_NETWORK, rootNetworkUuid) .setHeader(HEADER_UPDATE_TYPE, updateType) .setHeader(HEADER_ERROR, errorMessage) .setHeader(HEADER_USER_ID, userId) @@ -202,20 +205,22 @@ public void emitStudyError(UUID studyUuid, UUID nodeUuid, String updateType, Str } @PostCompletion - public void emitStudyChanged(UUID studyUuid, UUID nodeUuid, String updateType, Set substationsIds) { + public void emitStudyChanged(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String updateType, Set substationsIds) { sendUpdateMessage(MessageBuilder.withPayload("") .setHeader(HEADER_STUDY_UUID, studyUuid) .setHeader(HEADER_NODE, nodeUuid) + .setHeader(HEADER_ROOT_NETWORK, rootNetworkUuid) .setHeader(HEADER_UPDATE_TYPE, updateType) .setHeader(HEADER_UPDATE_TYPE_SUBSTATIONS_IDS, substationsIds) .build()); } @PostCompletion - public void emitStudyChanged(UUID studyUuid, UUID nodeUuid, String updateType, NetworkImpactsInfos networkImpactsInfos) { + public void emitStudyChanged(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String updateType, NetworkImpactsInfos networkImpactsInfos) { try { sendUpdateMessage(MessageBuilder.withPayload(objectMapper.writeValueAsString(networkImpactsInfos)).setHeader(HEADER_STUDY_UUID, studyUuid) .setHeader(HEADER_NODE, nodeUuid) + .setHeader(HEADER_ROOT_NETWORK, rootNetworkUuid) .setHeader(HEADER_UPDATE_TYPE, updateType) .build()); } catch (JsonProcessingException e) { @@ -280,10 +285,11 @@ public void emitNodesChanged(UUID studyUuid, Collection nodes) { } @PostCompletion - public void emitNodeBuildFailed(UUID studyUuid, UUID nodeUuid, String errorMessage) { + public void emitNodeBuildFailed(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String errorMessage) { sendUpdateMessage(MessageBuilder.withPayload("") .setHeader(HEADER_STUDY_UUID, studyUuid) .setHeader(HEADER_NODE, nodeUuid) + .setHeader(HEADER_ROOT_NETWORK, rootNetworkUuid) .setHeader(HEADER_UPDATE_TYPE, UPDATE_TYPE_BUILD_FAILED) .setHeader(HEADER_ERROR, errorMessage) .build()); @@ -312,11 +318,12 @@ public void emitSubtreeInserted(UUID studyUuid, UUID parentNodeSubtreeInserted, } @PostCompletion - public void emitNodeBuildStatusUpdated(UUID studyUuid, Collection nodes) { + public void emitNodeBuildStatusUpdated(UUID studyUuid, Collection nodes, UUID rootNetworkUuid) { sendUpdateMessage(MessageBuilder.withPayload("") .setHeader(HEADER_STUDY_UUID, studyUuid) .setHeader(HEADER_UPDATE_TYPE, NODE_BUILD_STATUS_UPDATED) .setHeader(HEADER_NODES, nodes) + .setHeader(HEADER_ROOT_NETWORK, rootNetworkUuid) .build() ); } @@ -406,12 +413,13 @@ public void emitElementUpdated(UUID elementUuid, String modifiedBy) { } @PostCompletion - public void emitStudyAlert(UUID studyUuid, UUID nodeUuid, String userId, StudyAlert studyAlert) { + public void emitStudyAlert(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String userId, StudyAlert studyAlert) { try { sendUpdateMessage(MessageBuilder.withPayload(objectMapper.writeValueAsString(studyAlert)) .setHeader(HEADER_USER_ID, userId) .setHeader(HEADER_STUDY_UUID, studyUuid) .setHeader(HEADER_NODE, nodeUuid) + .setHeader(HEADER_ROOT_NETWORK, rootNetworkUuid) .setHeader(HEADER_UPDATE_TYPE, STUDY_ALERT) .build() ); diff --git a/src/main/java/org/gridsuite/study/server/service/ConsumerService.java b/src/main/java/org/gridsuite/study/server/service/ConsumerService.java index c2b60a94c..44fafc672 100644 --- a/src/main/java/org/gridsuite/study/server/service/ConsumerService.java +++ b/src/main/java/org/gridsuite/study/server/service/ConsumerService.java @@ -113,7 +113,7 @@ public Consumer> consumeBuildResult() { NodeBuildStatus.from(networkModificationResult.getLastGroupApplicationStatus(), networkModificationResult.getApplicationStatus())); UUID studyUuid = networkModificationTreeService.getStudyUuidForNodeId(receiverObj.getNodeUuid()); - notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), NotificationService.UPDATE_TYPE_BUILD_COMPLETED, networkModificationResult.getImpactedSubstationsIds()); + notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), receiverObj.getRootNetworkUuid(), NotificationService.UPDATE_TYPE_BUILD_COMPLETED, networkModificationResult.getImpactedSubstationsIds()); } catch (Exception e) { LOGGER.error(e.toString()); } @@ -137,7 +137,7 @@ public Consumer> consumeBuildStopped() { // send notification UUID studyUuid = networkModificationTreeService.getStudyUuidForNodeId(receiverObj.getNodeUuid()); - notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), NotificationService.UPDATE_TYPE_BUILD_CANCELLED); + notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), receiverObj.getRootNetworkUuid(), NotificationService.UPDATE_TYPE_BUILD_CANCELLED); } catch (JsonProcessingException e) { LOGGER.error(e.toString()); } @@ -161,7 +161,7 @@ public Consumer> consumeBuildFailed() { // send notification UUID studyUuid = networkModificationTreeService.getStudyUuidForNodeId(receiverObj.getNodeUuid()); - notificationService.emitNodeBuildFailed(studyUuid, receiverObj.getNodeUuid(), message.getHeaders().get(HEADER_MESSAGE, String.class)); + notificationService.emitNodeBuildFailed(studyUuid, receiverObj.getNodeUuid(), receiverObj.getRootNetworkUuid(), message.getHeaders().get(HEADER_MESSAGE, String.class)); } catch (JsonProcessingException e) { LOGGER.error(e.toString()); } @@ -422,6 +422,7 @@ public void consumeCalculationFailed(Message msg, ComputationType comput notificationService.emitStudyError( studyUuid, receiverObj.getNodeUuid(), + receiverObj.getRootNetworkUuid(), computationType.getUpdateFailedType(), errorMessage, userId); @@ -442,7 +443,7 @@ public void consumeCalculationStopped(Message msg, ComputationType compu rootNetworkNodeInfoService.updateComputationResultUuid(receiverObj.getNodeUuid(), receiverObj.getRootNetworkUuid(), null, computationType); UUID studyUuid = networkModificationTreeService.getStudyUuidForNodeId(receiverObj.getNodeUuid()); // send notification for stopped computation - notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), computationType.getUpdateStatusType()); + notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), receiverObj.getRootNetworkUuid(), computationType.getUpdateStatusType()); LOGGER.info("{} stopped for node '{}'", computationType.getLabel(), receiverObj.getNodeUuid()); } catch (JsonProcessingException e) { @@ -464,6 +465,7 @@ public void consumeCalculationCancelFailed(Message msg, ComputationType notificationService.emitStudyError( studyUuid, receiverObj.getNodeUuid(), + receiverObj.getRootNetworkUuid(), updateType, errorMessage, userId @@ -489,8 +491,8 @@ public void consumeCalculationResult(Message msg, ComputationType comput UUID studyUuid = networkModificationTreeService.getStudyUuidForNodeId(receiverObj.getNodeUuid()); // send notifications - notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), computationType.getUpdateStatusType()); - notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), computationType.getUpdateResultType()); + notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), receiverObj.getRootNetworkUuid(), computationType.getUpdateStatusType()); + notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), receiverObj.getRootNetworkUuid(), computationType.getUpdateResultType()); })); } diff --git a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java index 867802011..347722b55 100644 --- a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java +++ b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java @@ -685,7 +685,7 @@ public void invalidateBuild(UUID nodeUuid, UUID rootNetworkUuid, boolean invalid } }); - notificationService.emitNodeBuildStatusUpdated(studyId, changedNodes.stream().distinct().collect(Collectors.toList())); + notificationService.emitNodeBuildStatusUpdated(studyId, changedNodes.stream().distinct().collect(Collectors.toList()), rootNetworkUuid); } @Transactional @@ -702,7 +702,7 @@ public void invalidateBuildOfNodeOnly(UUID nodeUuid, UUID rootNetworkUuid, boole } ); - notificationService.emitNodeBuildStatusUpdated(studyId, changedNodes.stream().distinct().collect(Collectors.toList())); + notificationService.emitNodeBuildStatusUpdated(studyId, changedNodes.stream().distinct().collect(Collectors.toList()), rootNetworkUuid); } private void invalidateChildrenBuildStatus(UUID nodeUuid, UUID rootNetworkUuid, List changedNodes, InvalidateNodeInfos invalidateNodeInfos, @@ -743,7 +743,7 @@ public void updateNodeBuildStatus(UUID nodeUuid, UUID rootNetworkUuid, NodeBuild rootNetworkNodeInfoEntity.setNodeBuildStatus(newNodeStatus); changedNodes.add(nodeUuid); - notificationService.emitNodeBuildStatusUpdated(studyId, changedNodes); + notificationService.emitNodeBuildStatusUpdated(studyId, changedNodes, rootNetworkUuid); } @Transactional(readOnly = true) diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index 96fc1bbe2..81fb7105c 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -720,7 +720,7 @@ public UUID runLoadFlow(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, Str UUID result = loadflowService.runLoadFlow(nodeUuid, rootNetworkUuid, networkUuid, variantId, lfParametersUuid, lfReportUuid, userId, limitReduction); updateComputationResultUuid(nodeUuid, rootNetworkUuid, result, LOAD_FLOW); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_LOADFLOW_STATUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_LOADFLOW_STATUS); return result; } @@ -810,7 +810,7 @@ public String getSecurityAnalysisParametersValues(UUID studyUuid) { public boolean setSecurityAnalysisParametersValues(UUID studyUuid, String parameters, String userId) { StudyEntity studyEntity = studyRepository.findById(studyUuid).orElseThrow(() -> new StudyException(STUDY_NOT_FOUND)); boolean userProfileIssue = createOrUpdateSecurityAnalysisParameters(studyUuid, studyEntity, parameters, userId); - notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS); + notificationService.emitStudyChanged(studyUuid, null, null, NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS); notificationService.emitElementUpdated(studyUuid, userId); notificationService.emitComputationParamsChanged(studyUuid, SECURITY_ANALYSIS); return userProfileIssue; @@ -833,11 +833,11 @@ public boolean setLoadFlowParameters(UUID studyUuid, String parameters, String u invalidateSensitivityAnalysisStatusOnAllNodes(studyUuid); invalidateNonEvacuatedEnergyAnalysisStatusOnAllNodes(studyUuid); invalidateDynamicSimulationStatusOnAllNodes(studyUuid); - notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_LOADFLOW_STATUS); - notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS); - notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS); - notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS); - notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); + notificationService.emitStudyChanged(studyUuid, null, null, NotificationService.UPDATE_TYPE_LOADFLOW_STATUS); + notificationService.emitStudyChanged(studyUuid, null, null, NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS); + notificationService.emitStudyChanged(studyUuid, null, null, NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS); + notificationService.emitStudyChanged(studyUuid, null, null, NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS); + notificationService.emitStudyChanged(studyUuid, null, null, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); notificationService.emitElementUpdated(studyUuid, userId); notificationService.emitComputationParamsChanged(studyUuid, LOAD_FLOW); return userProfileIssue; @@ -869,7 +869,7 @@ public void updateLoadFlowProvider(UUID studyUuid, String provider, String userI updateProvider(studyUuid, userId, studyEntity -> { loadflowService.updateLoadFlowProvider(studyEntity.getLoadFlowParametersUuid(), provider); invalidateLoadFlowStatusOnAllNodes(studyUuid); - notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_LOADFLOW_STATUS); + notificationService.emitStudyChanged(studyUuid, null, null, NotificationService.UPDATE_TYPE_LOADFLOW_STATUS); notificationService.emitComputationParamsChanged(studyUuid, LOAD_FLOW); }); @@ -883,7 +883,7 @@ public void updateSecurityAnalysisProvider(UUID studyUuid, String provider, Stri updateProvider(studyUuid, userId, studyEntity -> { securityAnalysisService.updateSecurityAnalysisProvider(studyEntity.getSecurityAnalysisParametersUuid(), provider); invalidateSecurityAnalysisStatusOnAllNodes(studyUuid); - notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS); + notificationService.emitStudyChanged(studyUuid, null, null, NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS); notificationService.emitComputationParamsChanged(studyUuid, SECURITY_ANALYSIS); }); } @@ -911,7 +911,7 @@ public void updateDynamicSimulationProvider(UUID studyUuid, String provider, Str updateProvider(studyUuid, userId, studyEntity -> { studyEntity.setDynamicSimulationProvider(provider != null ? provider : defaultDynamicSimulationProvider); invalidateDynamicSimulationStatusOnAllNodes(studyUuid); - notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); + notificationService.emitStudyChanged(studyUuid, null, null, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); notificationService.emitComputationParamsChanged(studyUuid, DYNAMIC_SIMULATION); }); } @@ -1009,7 +1009,7 @@ public UUID runSecurityAnalysis(UUID studyUuid, List contingencyListName UUID result = securityAnalysisService.runSecurityAnalysis(networkUuid, variantId, runSecurityAnalysisParametersInfos, new ReportInfos(saReportUuid, nodeUuid), receiver, userId); updateComputationResultUuid(nodeUuid, rootNetworkUuid, result, SECURITY_ANALYSIS); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS); return result; } @@ -1209,7 +1209,7 @@ public void updateDynamicSimulationParameters(UUID studyUuid, DynamicSimulationP studyEntity.ifPresent(studyEntity1 -> { studyEntity1.setDynamicSimulationParameters(dynamicSimulationParametersEntity); invalidateDynamicSimulationStatusOnAllNodes(studyUuid); - notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); + notificationService.emitStudyChanged(studyUuid, null, null, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); }); } @@ -1384,7 +1384,7 @@ private void assertCanBuildNode(@NonNull UUID studyUuid, @NonNull UUID rootNetwo @Transactional public void unbuildNode(@NonNull UUID studyUuid, @NonNull UUID nodeUuid, @NonNull UUID rootNetworkUuid) { invalidateBuild(studyUuid, nodeUuid, rootNetworkUuid, false, true, true); - emitAllComputationStatusChanged(studyUuid, nodeUuid); + emitAllComputationStatusChanged(studyUuid, nodeUuid, rootNetworkUuid); } public void stopBuild(@NonNull UUID nodeUuid, UUID rootNetworkUuid) { @@ -1508,15 +1508,14 @@ private void updateStatuses(UUID studyUuid, UUID nodeUuid, boolean invalidateOnl updateStatuses(studyUuid, nodeUuid, invalidateOnlyChildrenBuildStatus, true, true); } - // TODO Need to deal with all root networks private void updateStatuses(UUID studyUuid, UUID nodeUuid, boolean invalidateOnlyChildrenBuildStatus, boolean invalidateBuild, boolean deleteVoltageInitResults) { - if (invalidateBuild) { - //TODO: to implement better, this is not really optimized - rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> { - invalidateBuild(studyUuid, nodeUuid, rootNetworkEntity.getId(), invalidateOnlyChildrenBuildStatus, false, deleteVoltageInitResults); - }); - } - emitAllComputationStatusChanged(studyUuid, nodeUuid); + rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> { + UUID rootNetworkUuid = rootNetworkEntity.getId(); + if (invalidateBuild) { + invalidateBuild(studyUuid, nodeUuid, rootNetworkUuid, invalidateOnlyChildrenBuildStatus, false, deleteVoltageInitResults); + } + emitAllComputationStatusChanged(studyUuid, nodeUuid, rootNetworkUuid); + }); } @Transactional @@ -1529,7 +1528,6 @@ public void deleteNetworkModifications(UUID studyUuid, UUID nodeUuid, List } UUID groupId = networkModificationTreeService.getModificationGroupUuid(nodeUuid); networkModificationService.deleteModifications(groupId, modificationsUuids); - updateStatuses(studyUuid, nodeUuid, false, false, false); } finally { notificationService.emitEndDeletionEquipmentNotification(studyUuid, nodeUuid, childrenUuids); @@ -1872,7 +1870,7 @@ private void emitNetworkModificationImpacts(UUID studyUuid, UUID nodeUuid, UUID .map(impact -> impact.getElementType().name()) .collect(Collectors.toSet()); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_STUDY, + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_STUDY, NetworkImpactsInfos.builder() .deletedEquipments(deletionsInfos) .impactedSubstationsIds(networkModificationResult.getImpactedSubstationsIds()) @@ -1907,7 +1905,7 @@ public UUID runSensitivityAnalysis(UUID studyUuid, UUID nodeUuid, UUID rootNetwo UUID result = sensitivityAnalysisService.runSensitivityAnalysis(nodeUuid, rootNetworkUuid, networkUuid, variantId, sensiReportUuid, userId, study.getSensitivityAnalysisParametersUuid(), study.getLoadFlowParametersUuid()); updateComputationResultUuid(nodeUuid, rootNetworkUuid, result, SENSITIVITY_ANALYSIS); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS); return result; } @@ -1924,7 +1922,7 @@ public UUID runShortCircuit(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, networkModificationTreeService.updateComputationReportUuid(nodeUuid, rootNetworkUuid, computationType, scReportUuid); final UUID result = shortCircuitService.runShortCircuit(nodeUuid, rootNetworkUuid, networkUuid, variantId, busId.orElse(null), parametersUuid, scReportUuid, userId); updateComputationResultUuid(nodeUuid, rootNetworkUuid, result, computationType); - notificationService.emitStudyChanged(studyUuid, nodeUuid, + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, busId.isEmpty() ? NotificationService.UPDATE_TYPE_SHORT_CIRCUIT_STATUS : NotificationService.UPDATE_TYPE_ONE_BUS_SHORT_CIRCUIT_STATUS); return result; } @@ -1943,7 +1941,7 @@ public UUID runVoltageInit(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, UUID result = voltageInitService.runVoltageInit(networkUuid, variantId, studyEntity.getVoltageInitParametersUuid(), reportUuid, nodeUuid, rootNetworkUuid, userId); updateComputationResultUuid(nodeUuid, rootNetworkUuid, result, VOLTAGE_INITIALIZATION); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_VOLTAGE_INIT_STATUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_VOLTAGE_INIT_STATUS); return result; } @@ -1958,7 +1956,7 @@ public boolean setVoltageInitParameters(UUID studyUuid, StudyVoltageInitParamete voltageInitParameters.setApplyModifications(parameters.isApplyModifications()); } boolean userProfileIssue = createOrUpdateVoltageInitParameters(studyEntity, parameters.getComputationParameters(), userId); - notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_VOLTAGE_INIT_STATUS); + notificationService.emitStudyChanged(studyUuid, null, null, NotificationService.UPDATE_TYPE_VOLTAGE_INIT_STATUS); notificationService.emitElementUpdated(studyUuid, userId); notificationService.emitComputationParamsChanged(studyUuid, VOLTAGE_INITIALIZATION); return userProfileIssue; @@ -2023,7 +2021,7 @@ public EventInfos getDynamicSimulationEvent(UUID nodeUuid, String equipmentId) { private void postProcessEventCrud(UUID studyUuid, UUID nodeUuid) { // for delete old result and refresh dynamic simulation run button in UI invalidateDynamicSimulationStatusOnAllNodes(studyUuid); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, null, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); } @Transactional @@ -2106,7 +2104,7 @@ public UUID runDynamicSimulation(UUID studyUuid, UUID nodeUuid, UUID rootNetwork // update result uuid and notification updateComputationResultUuid(nodeUuid, rootNetworkUuid, dynamicSResultUuid, DYNAMIC_SIMULATION); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); return dynamicSResultUuid; } @@ -2149,7 +2147,7 @@ public void copyVoltageInitModifications(UUID studyUuid, UUID nodeUuid, UUID roo // invalidate the whole subtree except the target node (we have built this node during the duplication) networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, nodeUuid, rootNetworkUuid, modificationResult)); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_VOLTAGE_INIT_RESULT); // send notification voltage init result has changed + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_VOLTAGE_INIT_RESULT); // send notification voltage init result has changed updateStatuses(studyUuid, nodeUuid, true, true, false); // do not delete the voltage init results } finally { notificationService.emitEndModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids); @@ -2167,7 +2165,7 @@ public String getSensitivityAnalysisParameters(UUID studyUuid) { @Transactional public boolean setSensitivityAnalysisParameters(UUID studyUuid, String parameters, String userId) { boolean userProfileIssue = createOrUpdateSensitivityAnalysisParameters(studyUuid, parameters, userId); - notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS); + notificationService.emitStudyChanged(studyUuid, null, null, NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS); notificationService.emitElementUpdated(studyUuid, userId); notificationService.emitComputationParamsChanged(studyUuid, SENSITIVITY_ANALYSIS); return userProfileIssue; @@ -2233,7 +2231,7 @@ public void updateNonEvacuatedEnergyParameters(UUID studyUuid, NonEvacuatedEnerg @Transactional public void invalidateLoadFlowStatus(UUID studyUuid, String userId) { invalidateLoadFlowStatusOnAllNodes(studyUuid); - notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_LOADFLOW_STATUS); + notificationService.emitStudyChanged(studyUuid, null, null, NotificationService.UPDATE_TYPE_LOADFLOW_STATUS); notificationService.emitElementUpdated(studyUuid, userId); } @@ -2247,8 +2245,8 @@ public void invalidateShortCircuitStatusOnAllNodes(UUID studyUuid) { @Transactional public void invalidateShortCircuitStatus(UUID studyUuid) { invalidateShortCircuitStatusOnAllNodes(studyUuid); - notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_SHORT_CIRCUIT_STATUS); - notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_ONE_BUS_SHORT_CIRCUIT_STATUS); + notificationService.emitStudyChanged(studyUuid, null, null, NotificationService.UPDATE_TYPE_SHORT_CIRCUIT_STATUS); + notificationService.emitStudyChanged(studyUuid, null, null, NotificationService.UPDATE_TYPE_ONE_BUS_SHORT_CIRCUIT_STATUS); } public UUID runNonEvacuatedEnergy(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String userId) { @@ -2301,7 +2299,7 @@ public UUID runNonEvacuatedEnergy(UUID studyUuid, UUID nodeUuid, UUID rootNetwor UUID result = nonEvacuatedEnergyService.runNonEvacuatedEnergy(nodeUuid, rootNetworkUuid, networkUuid, variantId, reportUuid, provider, nonEvacuatedEnergyInputData, studyEntity.getLoadFlowParametersUuid(), userId); updateComputationResultUuid(nodeUuid, rootNetworkUuid, result, NON_EVACUATED_ENERGY_ANALYSIS); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS); return result; } @@ -2310,7 +2308,7 @@ public void updateNonEvacuatedEnergyProvider(UUID studyUuid, String provider, St updateProvider(studyUuid, userId, studyEntity -> { studyEntity.setNonEvacuatedEnergyProvider(provider != null ? provider : defaultNonEvacuatedEnergyProvider); invalidateNonEvacuatedEnergyAnalysisStatusOnAllNodes(studyUuid); - notificationService.emitStudyChanged(studyUuid, null, NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS); + notificationService.emitStudyChanged(studyUuid, null, null, NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS); notificationService.emitComputationParamsChanged(studyUuid, NON_EVACUATED_ENERGY_ANALYSIS); }); } @@ -2321,16 +2319,16 @@ public String getNonEvacuatedEnergyProvider(UUID studyUuid) { .orElse(""); } - private void emitAllComputationStatusChanged(UUID studyUuid, UUID nodeUuid) { - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_LOADFLOW_STATUS); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_SHORT_CIRCUIT_STATUS); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_ONE_BUS_SHORT_CIRCUIT_STATUS); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_VOLTAGE_INIT_STATUS); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_STATE_ESTIMATION_STATUS); + private void emitAllComputationStatusChanged(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid) { + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_LOADFLOW_STATUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_SHORT_CIRCUIT_STATUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_ONE_BUS_SHORT_CIRCUIT_STATUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_VOLTAGE_INIT_STATUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_STATE_ESTIMATION_STATUS); } public String evaluateFilter(UUID nodeUuid, UUID rootNetworkUuid, boolean inUpstreamBuiltParentNode, String filter) { @@ -2369,7 +2367,7 @@ public UUID runStateEstimation(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUu UUID result = stateEstimationService.runStateEstimation(networkUuid, variantId, new ReportInfos(reportUuid, nodeUuid), receiver, userId); updateComputationResultUuid(nodeUuid, rootNetworkUuid, result, STATE_ESTIMATION); - notificationService.emitStudyChanged(studyUuid, nodeUuid, NotificationService.UPDATE_TYPE_STATE_ESTIMATION_STATUS); + notificationService.emitStudyChanged(studyUuid, nodeUuid, rootNetworkUuid, NotificationService.UPDATE_TYPE_STATE_ESTIMATION_STATUS); return result; } diff --git a/src/main/java/org/gridsuite/study/server/service/VoltageInitResultConsumer.java b/src/main/java/org/gridsuite/study/server/service/VoltageInitResultConsumer.java index 0baaa34f3..e60eae778 100644 --- a/src/main/java/org/gridsuite/study/server/service/VoltageInitResultConsumer.java +++ b/src/main/java/org/gridsuite/study/server/service/VoltageInitResultConsumer.java @@ -49,7 +49,7 @@ private void checkReactiveSlacksOverThreshold(Message msg, UUID studyUui if (Boolean.TRUE.equals(alert)) { String userId = msg.getHeaders().get(HEADER_USER_ID, String.class); Double alertThreshold = msg.getHeaders().get(HEADER_REACTIVE_SLACKS_THRESHOLD_VALUE, Double.class); - notificationService.emitStudyAlert(studyUuid, nodeReceiver.getNodeUuid(), userId, new StudyAlert(AlertLevel.WARNING, HEADER_REACTIVE_SLACKS_OVER_THRESHOLD, Map.of("threshold", alertThreshold.toString()))); + notificationService.emitStudyAlert(studyUuid, nodeReceiver.getNodeUuid(), nodeReceiver.getRootNetworkUuid(), userId, new StudyAlert(AlertLevel.WARNING, HEADER_REACTIVE_SLACKS_OVER_THRESHOLD, Map.of("threshold", alertThreshold.toString()))); } }); } diff --git a/src/test/java/org/gridsuite/study/server/service/StudyServiceDynamicSimulationTest.java b/src/test/java/org/gridsuite/study/server/service/StudyServiceDynamicSimulationTest.java index 59cebde91..83fc79fa4 100644 --- a/src/test/java/org/gridsuite/study/server/service/StudyServiceDynamicSimulationTest.java +++ b/src/test/java/org/gridsuite/study/server/service/StudyServiceDynamicSimulationTest.java @@ -108,7 +108,7 @@ void setup() { willDoNothing().given(rootNetworkNodeInfoService).updateComputationResultUuid(NODE_UUID, ROOTNETWORK_UUID, RESULT_UUID, DYNAMIC_SIMULATION); // setup NotificationService mock - willDoNothing().given(notificationService).emitStudyChanged(STUDY_UUID, NODE_UUID, UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); + willDoNothing().given(notificationService).emitStudyChanged(STUDY_UUID, NODE_UUID, ROOTNETWORK_UUID, UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); } @Test From 544ef3343748e1652c132d28ab6b6a526a0ce513 Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Tue, 17 Dec 2024 12:15:40 +0100 Subject: [PATCH 04/17] feat: add endpoint to get all root networks Signed-off-by: LE SAULNIER Kevin --- .../study/server/StudyController.java | 7 +++++ .../server/dto/RootNetworkMinimalInfos.java | 5 +++ .../RootNetworkCreationRequestRepository.java | 2 ++ .../server/service/RootNetworkService.java | 14 +++++++++ .../study/server/RootNetworkTest.java | 31 +++++++++++++++++++ 5 files changed, 59 insertions(+) create mode 100644 src/main/java/org/gridsuite/study/server/dto/RootNetworkMinimalInfos.java diff --git a/src/main/java/org/gridsuite/study/server/StudyController.java b/src/main/java/org/gridsuite/study/server/StudyController.java index 078c36ef1..fae7448bd 100644 --- a/src/main/java/org/gridsuite/study/server/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/StudyController.java @@ -178,6 +178,13 @@ public ResponseEntity deleteStudy(@PathVariable("studyUuid") UUID studyUui return ResponseEntity.ok().build(); } + @GetMapping(value = "/studies/{studyUuid}/root-networks") + @Operation(summary = "Get root networks for study") + @ApiResponse(responseCode = "200", description = "List of root networks") + public ResponseEntity> getRootNetworks(@PathVariable("studyUuid") UUID studyUuid) { + return ResponseEntity.ok().body(rootNetworkService.getRootNetworks(studyUuid)); + } + @PostMapping(value = "/studies/{studyUuid}/root-networks") @Operation(summary = "Create root network for study") @ApiResponse(responseCode = "200", description = "Root network created") diff --git a/src/main/java/org/gridsuite/study/server/dto/RootNetworkMinimalInfos.java b/src/main/java/org/gridsuite/study/server/dto/RootNetworkMinimalInfos.java new file mode 100644 index 000000000..e06f165d5 --- /dev/null +++ b/src/main/java/org/gridsuite/study/server/dto/RootNetworkMinimalInfos.java @@ -0,0 +1,5 @@ +package org.gridsuite.study.server.dto; + +import java.util.UUID; + +public record RootNetworkMinimalInfos(UUID rootNetworkUuid, boolean isCreating) { } diff --git a/src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkCreationRequestRepository.java b/src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkCreationRequestRepository.java index b63100534..3263c0d56 100644 --- a/src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkCreationRequestRepository.java +++ b/src/main/java/org/gridsuite/study/server/repository/rootnetwork/RootNetworkCreationRequestRepository.java @@ -8,7 +8,9 @@ import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; import java.util.UUID; public interface RootNetworkCreationRequestRepository extends JpaRepository { + List findAllByStudyUuid(UUID studyUuid); } diff --git a/src/main/java/org/gridsuite/study/server/service/RootNetworkService.java b/src/main/java/org/gridsuite/study/server/service/RootNetworkService.java index 32feb32b2..f963dad87 100644 --- a/src/main/java/org/gridsuite/study/server/service/RootNetworkService.java +++ b/src/main/java/org/gridsuite/study/server/service/RootNetworkService.java @@ -14,6 +14,7 @@ import org.gridsuite.study.server.dto.CaseInfos; import org.gridsuite.study.server.dto.NetworkInfos; import org.gridsuite.study.server.dto.RootNetworkInfos; +import org.gridsuite.study.server.dto.RootNetworkMinimalInfos; import org.gridsuite.study.server.elasticsearch.EquipmentInfosService; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.rootnetwork.RootNetworkCreationRequestEntity; @@ -232,4 +233,17 @@ public Optional getCreationRequest(UUID rootNe public void deleteCreationRequest(RootNetworkCreationRequestEntity rootNetworkCreationRequestEntity) { rootNetworkCreationRequestRepository.delete(rootNetworkCreationRequestEntity); } + + public List getRootNetworks(UUID studyUuid) { + List result = new ArrayList<>(); + + // return RootNetworkMinimalInfos with isCreating as false when in rootNetworkRepository + result.addAll(rootNetworkRepository.findAllByStudyId(studyUuid).stream() + .map(rootNetworkEntity -> new RootNetworkMinimalInfos(rootNetworkEntity.getId(), false)).toList()); + // return RootNetworkMinimalInfos with isCreating as true when in rootNetworkCreationRequestRepository + result.addAll(rootNetworkCreationRequestRepository.findAllByStudyUuid(studyUuid).stream() + .map(rootNetworkCreationEntity -> new RootNetworkMinimalInfos(rootNetworkCreationEntity.getId(), true)).toList()); + + return result; + } } diff --git a/src/test/java/org/gridsuite/study/server/RootNetworkTest.java b/src/test/java/org/gridsuite/study/server/RootNetworkTest.java index 32b6d1524..d99f4463f 100644 --- a/src/test/java/org/gridsuite/study/server/RootNetworkTest.java +++ b/src/test/java/org/gridsuite/study/server/RootNetworkTest.java @@ -7,6 +7,7 @@ package org.gridsuite.study.server; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.client.WireMock; @@ -497,6 +498,36 @@ void testUpdateRootNetworkConsumer() throws Exception { true); } + @Test + void getRootNetworks() throws Exception { + // create study with one root node, two network modification node and a root network + StudyEntity studyEntity = TestUtils.createDummyStudy(NETWORK_UUID, CASE_UUID, CASE_NAME, CASE_FORMAT, REPORT_UUID); + studyRepository.save(studyEntity); + + // create a second root network + RootNetworkEntity rootNetworkEntity = rootNetworkService.createRootNetwork(studyEntity, RootNetworkInfos.builder() + .caseInfos(new CaseInfos(CASE_UUID2, CASE_NAME2, CASE_FORMAT2)) + .networkInfos(new NetworkInfos(NETWORK_UUID2, NETWORK_ID2)) + .reportUuid(REPORT_UUID2) + .id(UUID.randomUUID()) + .build()); + + // create a request of root network creation + UUID requestUuid = UUID.randomUUID(); + rootNetworkCreationRequestRepository.save(new RootNetworkCreationRequestEntity(requestUuid, studyEntity.getId(), USER_ID)); + + String response = mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks", studyEntity.getId())) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + List result = objectMapper.readValue(response, new TypeReference<>() { }); + assertEquals(3, result.size()); + + RootNetworkMinimalInfos requestRootNetwork = result.stream().filter(rootNetworkMinimalInfos -> rootNetworkMinimalInfos.rootNetworkUuid().equals(requestUuid)).findFirst().orElseThrow(() -> new Exception("this should be in the results")); + assertTrue(requestRootNetwork.isCreating()); + RootNetworkMinimalInfos createdRootNetwork = result.stream().filter(rootNetworkMinimalInfos -> rootNetworkMinimalInfos.rootNetworkUuid().equals(rootNetworkEntity.getId())).findFirst().orElseThrow(() -> new Exception("this should be in the results")); + assertFalse(createdRootNetwork.isCreating()); + } + private Map createConsumeCaseImportSucceededHeaders(String networkUuid, String networkId, String caseFormat, String caseName, CaseImportReceiver caseImportReceiver, Map importParameters) throws JsonProcessingException { Map headers = new HashMap<>(); headers.put("networkUuid", networkUuid); From 98598ce646f1a693ed7aa5a1d797003c5473b828 Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Tue, 17 Dec 2024 13:50:18 +0100 Subject: [PATCH 05/17] fix: remove most of getFirstRootNetwork in controller Signed-off-by: LE SAULNIER Kevin --- .../study/server/StudyController.java | 44 +++++++++---------- .../study/server/service/StudyService.java | 27 +++++++----- .../org/gridsuite/study/server/CaseTest.java | 8 +++- .../study/server/RootNetworkTest.java | 1 + .../study/server/StudyServiceTest.java | 22 +++++++--- .../org/gridsuite/study/server/StudyTest.java | 18 ++++---- .../server/SupervisionControllerTest.java | 8 +++- 7 files changed, 78 insertions(+), 50 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/StudyController.java b/src/main/java/org/gridsuite/study/server/StudyController.java index fae7448bd..3d4b1084c 100644 --- a/src/main/java/org/gridsuite/study/server/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/StudyController.java @@ -109,12 +109,12 @@ public ResponseEntity> getStudyList() { return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getStudies()); } - @GetMapping(value = "/studies/{studyUuid}/case/name") + @GetMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/case/name") @Operation(summary = "Get study case name") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The study case name"), @ApiResponse(responseCode = "204", description = "The study has no case name attached")}) - public ResponseEntity getStudyCaseName(@PathVariable("studyUuid") UUID studyUuid) { - String studyCaseName = rootNetworkService.getCaseName(studyService.getStudyFirstRootNetworkUuid(studyUuid)); + public ResponseEntity getStudyCaseName(@PathVariable("studyUuid") UUID studyUuid, @PathVariable("rootNetworkUuid") UUID rootNetworkUuid) { + String studyCaseName = rootNetworkService.getCaseName(rootNetworkUuid); return StringUtils.isEmpty(studyCaseName) ? ResponseEntity.noContent().build() : ResponseEntity.ok().body(studyCaseName); } @@ -248,59 +248,60 @@ public ResponseEntity cutAndPasteNode(@PathVariable("studyUuid") UUID stud @Parameter(description = "The reference node to where we want to paste") @RequestParam("referenceNodeUuid") UUID referenceNodeUuid, @Parameter(description = "the position where the node will be pasted relative to the reference node") @RequestParam(name = "insertMode") InsertMode insertMode, @RequestHeader(HEADER_USER_ID) String userId) { - UUID rootNetworkUuid = studyService.getStudyFirstRootNetworkUuid(studyUuid); - studyService.moveStudyNode(studyUuid, nodeToCutUuid, rootNetworkUuid, referenceNodeUuid, insertMode, userId); + studyService.moveStudyNode(studyUuid, nodeToCutUuid, referenceNodeUuid, insertMode, userId); return ResponseEntity.ok().build(); } - @RequestMapping(value = "/studies/{studyUuid}/network", method = RequestMethod.HEAD) + @RequestMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/network", method = RequestMethod.HEAD) @Operation(summary = "check study root network existence") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "The network does exist"), @ApiResponse(responseCode = "204", description = "The network doesn't exist")}) - public ResponseEntity checkNetworkExistence(@PathVariable("studyUuid") UUID studyUuid) { - UUID networkUUID = rootNetworkService.getNetworkUuid(studyService.getStudyFirstRootNetworkUuid(studyUuid)); + public ResponseEntity checkNetworkExistence(@PathVariable("studyUuid") UUID studyUuid, @PathVariable("rootNetworkUuid") UUID rootNetworkUuid) { + UUID networkUUID = rootNetworkService.getNetworkUuid(rootNetworkUuid); return networkStoreService.doesNetworkExist(networkUUID) ? ResponseEntity.ok().build() : ResponseEntity.noContent().build(); } - @PostMapping(value = "/studies/{studyUuid}/network", params = {"caseUuid"}) + @PostMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/network", params = {"caseUuid"}) @Operation(summary = "recreate study network of a study from an existing case") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Study network recreation has started"), @ApiResponse(responseCode = "424", description = "The case doesn't exist")}) public ResponseEntity recreateNetworkFromCase(@PathVariable("studyUuid") UUID studyUuid, + @PathVariable("rootNetworkUuid") UUID rootNetworkUuid, @RequestBody(required = false) Map importParameters, @RequestParam(value = "caseUuid") UUID caseUuid, @Parameter(description = "case format") @RequestParam(name = "caseFormat", required = false) String caseFormat, @RequestHeader(HEADER_USER_ID) String userId) { - studyService.recreateNetwork(caseUuid, userId, studyUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid), caseFormat, importParameters); + studyService.recreateNetwork(caseUuid, userId, studyUuid, rootNetworkUuid, caseFormat, importParameters); return ResponseEntity.ok().build(); } - @PostMapping(value = "/studies/{studyUuid}/network") + @PostMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/network") @Operation(summary = "recreate study network of a study from its case") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Study network recreation has started"), @ApiResponse(responseCode = "424", description = "The study's case doesn't exist")}) public ResponseEntity recreateStudyNetwork(@PathVariable("studyUuid") UUID studyUuid, + @PathVariable("rootNetworkUuid") UUID rootNetworkUuid, @RequestHeader(HEADER_USER_ID) String userId, @Parameter(description = "case format") @RequestParam(name = "caseFormat", required = false) String caseFormat ) { - studyService.recreateNetwork(userId, studyUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid), caseFormat); + studyService.recreateNetwork(userId, studyUuid, rootNetworkUuid, caseFormat); return ResponseEntity.ok().build(); } - @GetMapping(value = "/studies/{studyUuid}/indexation/status") + @GetMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/indexation/status") @Operation(summary = "check study indexation") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "The study indexation status"), @ApiResponse(responseCode = "204", description = "The study indexation status doesn't exist"), @ApiResponse(responseCode = "404", description = "The study or network doesn't exist")}) - public ResponseEntity checkStudyIndexationStatus(@PathVariable("studyUuid") UUID studyUuid) { - String result = studyService.getStudyIndexationStatus(studyUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid)).name(); + public ResponseEntity checkStudyIndexationStatus(@PathVariable("studyUuid") UUID studyUuid, @PathVariable("rootNetworkUuid") UUID rootNetworkUuid) { + String result = studyService.getStudyIndexationStatus(studyUuid, rootNetworkUuid).name(); return result != null ? ResponseEntity.ok().body(result) : ResponseEntity.noContent().build(); } @@ -315,8 +316,7 @@ public ResponseEntity cutAndPasteNodeSubtree(@PathVariable("studyUuid") UU @Parameter(description = "The parent node of the subtree we want to cut") @RequestParam("subtreeToCutParentNodeUuid") UUID subtreeToCutParentNodeUuid, @Parameter(description = "The reference node to where we want to paste") @RequestParam("referenceNodeUuid") UUID referenceNodeUuid, @RequestHeader(HEADER_USER_ID) String userId) { - UUID rootNetworkUuid = studyService.getStudyFirstRootNetworkUuid(studyUuid); - studyService.moveStudySubtree(studyUuid, subtreeToCutParentNodeUuid, rootNetworkUuid, referenceNodeUuid, userId); + studyService.moveStudySubtree(studyUuid, subtreeToCutParentNodeUuid, referenceNodeUuid, userId); return ResponseEntity.ok().build(); } @@ -1274,8 +1274,7 @@ public ResponseEntity stashNode(@Parameter(description = "study uuid") @Pa @Parameter(description = "id of child to delete (move to trash)") @PathVariable("id") UUID nodeId, @Parameter(description = "stashChildren") @RequestParam(value = "stashChildren", defaultValue = "false") boolean stashChildren, @RequestHeader(HEADER_USER_ID) String userId) { - UUID rootNetworkUuid = studyService.getStudyFirstRootNetworkUuid(studyUuid); - studyService.stashNode(studyUuid, nodeId, rootNetworkUuid, stashChildren, userId); + studyService.stashNode(studyUuid, nodeId, stashChildren, userId); return ResponseEntity.ok().build(); } @@ -1436,11 +1435,12 @@ public ResponseEntity getDefaultDynamicSimulationProvider() { return ResponseEntity.ok().body(studyService.getDefaultDynamicSimulationProvider()); } - @PostMapping(value = "/studies/{studyUuid}/reindex-all") + @PostMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/reindex-all") @Operation(summary = "reindex the study") @ApiResponse(responseCode = "200", description = "Study reindexed") - public ResponseEntity reindexStudy(@Parameter(description = "study uuid") @PathVariable("studyUuid") UUID studyUuid) { - studyService.reindexStudy(studyUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid)); + public ResponseEntity reindexStudy(@Parameter(description = "study uuid") @PathVariable("studyUuid") UUID studyUuid, + @Parameter(description = "root network uuid") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid) { + studyService.reindexStudy(studyUuid, rootNetworkUuid); return ResponseEntity.ok().build(); } diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index 81fb7105c..09cd561ce 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -1402,7 +1402,7 @@ public void duplicateStudyNode(UUID sourceStudyUuid, UUID targetStudyUuid, UUID } @Transactional - public void moveStudyNode(UUID studyUuid, UUID nodeToMoveUuid, UUID rootNetworkUuid, UUID referenceNodeUuid, InsertMode insertMode, String userId) { + public void moveStudyNode(UUID studyUuid, UUID nodeToMoveUuid, UUID referenceNodeUuid, InsertMode insertMode, String userId) { List oldChildren = null; checkStudyContainsNode(studyUuid, nodeToMoveUuid); checkStudyContainsNode(studyUuid, referenceNodeUuid); @@ -1420,7 +1420,9 @@ public void moveStudyNode(UUID studyUuid, UUID nodeToMoveUuid, UUID rootNetworkU updateStatuses(studyUuid, nodeToMoveUuid, false, true, true); oldChildren.forEach(child -> updateStatuses(studyUuid, child.getIdNode(), false, true, true)); } else { - invalidateBuild(studyUuid, nodeToMoveUuid, rootNetworkUuid, false, true, true); + rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> { + invalidateBuild(studyUuid, nodeToMoveUuid, rootNetworkEntity.getId(), false, true, true); + }); } notificationService.emitElementUpdated(studyUuid, userId); } @@ -1438,7 +1440,7 @@ public void duplicateStudySubtree(UUID sourceStudyUuid, UUID targetStudyUuid, UU } @Transactional - public void moveStudySubtree(UUID studyUuid, UUID parentNodeToMoveUuid, UUID rootNetworkUuid, UUID referenceNodeUuid, String userId) { + public void moveStudySubtree(UUID studyUuid, UUID parentNodeToMoveUuid, UUID referenceNodeUuid, String userId) { checkStudyContainsNode(studyUuid, parentNodeToMoveUuid); checkStudyContainsNode(studyUuid, referenceNodeUuid); @@ -1448,18 +1450,21 @@ public void moveStudySubtree(UUID studyUuid, UUID parentNodeToMoveUuid, UUID roo } networkModificationTreeService.moveStudySubtree(parentNodeToMoveUuid, referenceNodeUuid); - if (networkModificationTreeService.getNodeBuildStatus(parentNodeToMoveUuid, rootNetworkUuid).isBuilt()) { - updateStatuses(studyUuid, parentNodeToMoveUuid, false, true, true); - } - allChildren.stream() + rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> { + UUID rootNetworkUuid = rootNetworkEntity.getId(); + if (networkModificationTreeService.getNodeBuildStatus(parentNodeToMoveUuid, rootNetworkUuid).isBuilt()) { + updateStatuses(studyUuid, parentNodeToMoveUuid, false, true, true); + } + allChildren.stream() .filter(childUuid -> networkModificationTreeService.getNodeBuildStatus(childUuid, rootNetworkUuid).isBuilt()) .forEach(childUuid -> updateStatuses(studyUuid, childUuid, false, true, true)); + }); + notificationService.emitSubtreeMoved(studyUuid, parentNodeToMoveUuid, referenceNodeUuid); notificationService.emitElementUpdated(studyUuid, userId); } - // TODO Need to deal with all root networks public void invalidateBuild(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, boolean invalidateOnlyChildrenBuildStatus, boolean invalidateOnlyTargetNode, boolean deleteVoltageInitResults) { AtomicReference startTime = new AtomicReference<>(null); startTime.set(System.nanoTime()); @@ -1639,11 +1644,13 @@ public void deleteNodes(UUID studyUuid, List nodeIds, boolean deleteChildr } @Transactional - public void stashNode(UUID studyUuid, UUID nodeId, UUID rootNetworkUuid, boolean stashChildren, String userId) { + public void stashNode(UUID studyUuid, UUID nodeId, boolean stashChildren, String userId) { AtomicReference startTime = new AtomicReference<>(null); startTime.set(System.nanoTime()); boolean invalidateChildrenBuild = stashChildren || networkModificationTreeService.hasModifications(nodeId, false); - invalidateBuild(studyUuid, nodeId, rootNetworkUuid, false, !invalidateChildrenBuild, true); + rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> { + invalidateBuild(studyUuid, nodeId, rootNetworkEntity.getId(), false, !invalidateChildrenBuild, true); + }); networkModificationTreeService.doStashNode(nodeId, stashChildren); if (startTime.get() != null) { diff --git a/src/test/java/org/gridsuite/study/server/CaseTest.java b/src/test/java/org/gridsuite/study/server/CaseTest.java index 51a6693d1..a852e76e2 100644 --- a/src/test/java/org/gridsuite/study/server/CaseTest.java +++ b/src/test/java/org/gridsuite/study/server/CaseTest.java @@ -18,6 +18,7 @@ import org.gridsuite.study.server.repository.StudyRepository; import org.gridsuite.study.server.service.CaseService; import org.gridsuite.study.server.service.NetworkModificationTreeService; +import org.gridsuite.study.server.utils.StudyTestUtils; import org.gridsuite.study.server.utils.TestUtils; import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch; import org.jetbrains.annotations.NotNull; @@ -74,6 +75,8 @@ class CaseTest { //output destinations private static final String STUDY_UPDATE_DESTINATION = "study.update"; + @Autowired + private StudyTestUtils studyTestUtils; @BeforeEach void setup(final MockWebServer server) { @@ -102,11 +105,12 @@ public MockResponse dispatch(RecordedRequest request) { void getCaseName() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, CASE_NAME); UUID study1Uuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid); - mockMvc.perform(get("/v1/studies/{studyUuid}/case/name", study1Uuid)).andExpectAll( + mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/case/name", study1Uuid, firstRootNetworkUuid)).andExpectAll( status().isOk(), content().string(CASE_NAME)); - mockMvc.perform(get("/v1/studies/{studyUuid}/case/name", UUID.randomUUID())) + mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/case/name", UUID.randomUUID(), UUID.randomUUID())) .andExpect(status().isNotFound()); } diff --git a/src/test/java/org/gridsuite/study/server/RootNetworkTest.java b/src/test/java/org/gridsuite/study/server/RootNetworkTest.java index d99f4463f..61f2dd7e7 100644 --- a/src/test/java/org/gridsuite/study/server/RootNetworkTest.java +++ b/src/test/java/org/gridsuite/study/server/RootNetworkTest.java @@ -542,5 +542,6 @@ private Map createConsumeCaseImportSucceededHeaders(String netwo @AfterEach void tearDown() { TestUtils.assertWiremockServerRequestsEmptyThenShutdown(wireMockServer); + rootNetworkCreationRequestRepository.deleteAll(); } } diff --git a/src/test/java/org/gridsuite/study/server/StudyServiceTest.java b/src/test/java/org/gridsuite/study/server/StudyServiceTest.java index cf779f440..8c27137b7 100644 --- a/src/test/java/org/gridsuite/study/server/StudyServiceTest.java +++ b/src/test/java/org/gridsuite/study/server/StudyServiceTest.java @@ -21,6 +21,7 @@ import org.gridsuite.study.server.service.NetworkModificationTreeService; import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService; import org.gridsuite.study.server.utils.SendInput; +import org.gridsuite.study.server.utils.StudyTestUtils; import org.gridsuite.study.server.utils.TestUtils; import org.gridsuite.study.server.utils.WireMockUtils; import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch; @@ -103,6 +104,9 @@ class StudyServiceTest { @Autowired private NetworkModificationTreeService networkModificationTreeService; + @Autowired + private StudyTestUtils studyTestUtils; + @MockBean private NetworkStoreService networkStoreService; @@ -135,7 +139,8 @@ void testCheckNetworkExistenceReturnsOk() throws Exception { importParameters.put("param2", "changedValue"); String userId = "userId"; UUID studyUuid = createStudy(userId, CASE_UUID, importParameters); - mockMvc.perform(head("/v1/studies/{studyUuid}/network", studyUuid) + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); + mockMvc.perform(head("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/network", studyUuid, firstRootNetworkUuid) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); } @@ -147,8 +152,9 @@ void testCheckNetworkExistenceReturnsNotContent() throws Exception { importParameters.put("param2", "changedValue"); String userId = "userId"; UUID studyUuid = createStudy(userId, CASE_UUID, importParameters); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); when(networkStoreService.getNetwork(NETWORK_UUID)).thenThrow(new PowsyblException("Network '" + NETWORK_UUID + "' not found")); - mockMvc.perform(head("/v1/studies/{studyUuid}/network", studyUuid) + mockMvc.perform(head("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/network", studyUuid, firstRootNetworkUuid) .header(USER_ID_HEADER, userId)) .andExpect(status().isNoContent()); } @@ -161,13 +167,14 @@ void testRecreateStudyNetworkWithStudyCaseAndImportParameters() throws Exception String userId = "userId"; UUID studyUuid = createStudy(userId, CASE_UUID, importParameters); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); UUID caseExistsStubId = wireMockUtils.stubCaseExists(CASE_UUID.toString(), true); CountDownLatch countDownLatch = new CountDownLatch(1); UUID postNetworkStubId = wireMockUtils.stubImportNetwork(CASE_UUID.toString(), importParameters, NETWORK_UUID.toString(), "20140116_0830_2D4_UX1_pst", null, "UCTE", "20140116_0830_2D4_UX1_pst.ucte", countDownLatch); UUID disableCaseExpirationStubId = wireMockUtils.stubDisableCaseExpiration(CASE_UUID.toString()); - mockMvc.perform(post("/v1/studies/{studyUuid}/network", studyUuid) + mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/network", studyUuid, firstRootNetworkUuid) .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); @@ -190,8 +197,9 @@ void testRecreateStudyNetworkWithMissingStudyCase() throws Exception { Map importParameters = new HashMap<>(); String userId = "userId"; UUID studyUuid = createStudy(userId, CASE_UUID, importParameters); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); UUID caseExistsStubId = wireMockUtils.stubCaseExists(CASE_UUID.toString(), false); - mockMvc.perform(post("/v1/studies/{studyUuid}/network", studyUuid) + mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/network", studyUuid, firstRootNetworkUuid) .header(USER_ID_HEADER, userId)) .andExpect(status().isFailedDependency()); wireMockUtils.verifyCaseExists(caseExistsStubId, CASE_UUID.toString()); @@ -202,6 +210,7 @@ void testRecreateStudyNetworkFromExistingCase() throws Exception { String userId = "userId"; Map importParameters = new HashMap<>(); UUID studyUuid = createStudy(userId, CASE_UUID, importParameters); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); Map newImportParameters = new HashMap<>(); importParameters.put("param1", "changedValue1, changedValue2"); @@ -212,7 +221,7 @@ void testRecreateStudyNetworkFromExistingCase() throws Exception { UUID postNetworkStubId = wireMockUtils.stubImportNetwork(CASE_UUID_STRING, newImportParameters, NETWORK_UUID.toString(), "20140116_0830_2D4_UX1_pst", null, "UCTE", "20140116_0830_2D4_UX1_pst.ucte", countDownLatch); UUID disableCaseExpirationStubId = wireMockUtils.stubDisableCaseExpiration(CASE_UUID.toString()); - mockMvc.perform(post("/v1/studies/{studyUuid}/network", studyUuid) + mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/network", studyUuid, firstRootNetworkUuid) .param(HEADER_IMPORT_PARAMETERS, objectWriter.writeValueAsString(newImportParameters)) .param("caseUuid", CASE_UUID_STRING) .header(USER_ID_HEADER, userId)) @@ -237,6 +246,7 @@ void testRecreateStudyNetworkFromUnexistingCase() throws Exception { String userId = "userId"; Map importParameters = new HashMap<>(); UUID studyUuid = createStudy(userId, CASE_UUID, importParameters); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); Map newImportParameters = new HashMap<>(); importParameters.put("param1", "changedValue1, changedValue2"); @@ -244,7 +254,7 @@ void testRecreateStudyNetworkFromUnexistingCase() throws Exception { UUID caseExistsStubId = wireMockUtils.stubCaseExists(CASE_UUID.toString(), false); - mockMvc.perform(post("/v1/studies/{studyUuid}/network", studyUuid) + mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/network", studyUuid, firstRootNetworkUuid) .param(HEADER_IMPORT_PARAMETERS, objectWriter.writeValueAsString(newImportParameters)) .param("caseUuid", CASE_UUID_STRING) .header(USER_ID_HEADER, userId)) diff --git a/src/test/java/org/gridsuite/study/server/StudyTest.java b/src/test/java/org/gridsuite/study/server/StudyTest.java index ee35b2bbe..51867035c 100644 --- a/src/test/java/org/gridsuite/study/server/StudyTest.java +++ b/src/test/java/org/gridsuite/study/server/StudyTest.java @@ -2563,15 +2563,16 @@ private void checkElementUpdatedMessageSent(UUID elementUuid, String userId) { @Test void reindexStudyTest(final MockWebServer server) throws Exception { - mockMvc.perform(post("/v1/studies/{studyUuid}/reindex-all", UUID.randomUUID())) + mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/reindex-all", UUID.randomUUID(), UUID.randomUUID())) .andExpect(status().isNotFound()); - mockMvc.perform(get("/v1/studies/{studyUuid}/indexation/status", UUID.randomUUID())) + mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/indexation/status", UUID.randomUUID(), UUID.randomUUID())) .andExpectAll(status().isNotFound()); UUID notExistingNetworkStudyUuid = createStudy(server, "userId", NOT_EXISTING_NETWORK_CASE_UUID); + UUID notExistingNetworkRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(notExistingNetworkStudyUuid); - mockMvc.perform(post("/v1/studies/{studyUuid}/reindex-all", notExistingNetworkStudyUuid)) + mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/reindex-all", notExistingNetworkStudyUuid, notExistingNetworkRootNetworkUuid)) .andExpect(status().isInternalServerError()); Message indexationStatusMessageOnGoing = output.receive(TIMEOUT, studyUpdateDestination); Message indexationStatusMessageNotIndexed = output.receive(TIMEOUT, studyUpdateDestination); @@ -2579,20 +2580,21 @@ void reindexStudyTest(final MockWebServer server) throws Exception { var requests = TestUtils.getRequestsWithBodyDone(1, server); assertTrue(requests.stream().anyMatch(r -> r.getPath().contains("/v1/networks/" + NOT_EXISTING_NETWORK_UUID + "/reindex-all"))); - mockMvc.perform(get("/v1/studies/{studyUuid}/indexation/status", notExistingNetworkStudyUuid)) + mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/indexation/status", notExistingNetworkStudyUuid, notExistingNetworkRootNetworkUuid)) .andExpectAll(status().isInternalServerError()); requests = TestUtils.getRequestsWithBodyDone(1, server); assertEquals(1, requests.stream().filter(r -> r.getPath().contains("/v1/networks/" + NOT_EXISTING_NETWORK_UUID + "/indexed-equipments")).count()); UUID study1Uuid = createStudy(server, "userId", CASE_UUID); + UUID study1RootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid); - mockMvc.perform(get("/v1/studies/{studyUuid}/indexation/status", study1Uuid)) + mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/indexation/status", study1Uuid, study1RootNetworkUuid)) .andExpectAll(status().isOk(), content().string("NOT_INDEXED")); indexationStatusMessageNotIndexed = output.receive(TIMEOUT, studyUpdateDestination); - mockMvc.perform(post("/v1/studies/{studyUuid}/reindex-all", study1Uuid)) + mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/reindex-all", study1Uuid, study1RootNetworkUuid)) .andExpect(status().isOk()); indexationStatusMessageOnGoing = output.receive(TIMEOUT, studyUpdateDestination); @@ -2600,7 +2602,7 @@ void reindexStudyTest(final MockWebServer server) throws Exception { assertEquals(study1Uuid, indexationStatusMessageDone.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.UPDATE_TYPE_INDEXATION_STATUS, indexationStatusMessageDone.getHeaders().get(HEADER_UPDATE_TYPE)); - mockMvc.perform(get("/v1/studies/{studyUuid}/indexation/status", study1Uuid)) + mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/indexation/status", study1Uuid, study1RootNetworkUuid)) .andExpectAll(status().isOk(), content().string("INDEXED")); @@ -2613,7 +2615,7 @@ void reindexStudyTest(final MockWebServer server) throws Exception { assertEquals(study1Uuid, buildStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.NODE_BUILD_STATUS_UPDATED, buildStatusMessage.getHeaders().get(HEADER_UPDATE_TYPE)); - mockMvc.perform(post("/v1/studies/{studyUuid}/reindex-all", study1Uuid)) + mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/reindex-all", study1Uuid, study1RootNetworkUuid)) .andExpect(status().is5xxServerError()); indexationStatusMessageOnGoing = output.receive(TIMEOUT, studyUpdateDestination); indexationStatusMessageNotIndexed = output.receive(TIMEOUT, studyUpdateDestination); diff --git a/src/test/java/org/gridsuite/study/server/SupervisionControllerTest.java b/src/test/java/org/gridsuite/study/server/SupervisionControllerTest.java index c905879ad..0c8eaa3fa 100644 --- a/src/test/java/org/gridsuite/study/server/SupervisionControllerTest.java +++ b/src/test/java/org/gridsuite/study/server/SupervisionControllerTest.java @@ -26,6 +26,7 @@ import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.StudyRepository; import org.gridsuite.study.server.service.*; +import org.gridsuite.study.server.utils.StudyTestUtils; import org.gridsuite.study.server.utils.TestUtils; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -88,6 +89,8 @@ class SupervisionControllerTest { @Autowired private RestClient restClient; + @Autowired + private StudyTestUtils studyTestUtils; private static EquipmentInfos toEquipmentInfos(Identifiable i) { return EquipmentInfos.builder() @@ -129,7 +132,7 @@ void tearDown() { private StudyEntity initStudy() throws Exception { StudyEntity study = insertDummyStudy(NETWORK_UUID, CASE_UUID, ""); - UUID rootNetworkUuid = studyService.getStudyFirstRootNetworkUuid(STUDY_UUID); + UUID rootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(STUDY_UUID); when(rootNetworkService.getNetworkUuid(rootNetworkUuid)).thenReturn(NETWORK_UUID); assertIndexationStatus(STUDY_UUID, StudyIndexationStatus.INDEXED.name()); @@ -153,7 +156,8 @@ private void assertIndexationCount(long expectedEquipmentsIndexationCount, long } private void assertIndexationStatus(UUID studyUuid, String status) throws Exception { - mockMvc.perform(get("/v1/studies/{studyUuid}/indexation/status", studyUuid)) + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); + mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/indexation/status", studyUuid, firstRootNetworkUuid)) .andExpectAll(status().isOk(), content().string(status)); } From 524986510d1e51a5e8ebe38e8c1ef49664360497 Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Wed, 18 Dec 2024 11:46:48 +0100 Subject: [PATCH 06/17] fix: root network creation Signed-off-by: LE SAULNIER Kevin --- .../study/server/SupervisionController.java | 8 ++-- .../service/NetworkConversionService.java | 17 +++++--- .../study/server/service/StudyService.java | 6 ++- .../gridsuite/study/server/LoadFlowTest.java | 2 +- .../study/server/NetworkModificationTest.java | 40 +++++++++---------- .../server/NetworkModificationTreeTest.java | 4 +- .../study/server/NonEvacuatedEnergyTest.java | 2 +- .../study/server/SecurityAnalysisTest.java | 2 +- .../study/server/SensitivityAnalysisTest.java | 2 +- .../study/server/ShortCircuitTest.java | 2 +- .../study/server/SingleLineDiagramTest.java | 2 +- .../study/server/StateEstimationTest.java | 2 +- .../StudyControllerDynamicSimulationTest.java | 2 +- .../org/gridsuite/study/server/StudyTest.java | 12 +++--- .../study/server/VoltageInitTest.java | 2 +- 15 files changed, 56 insertions(+), 49 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/SupervisionController.java b/src/main/java/org/gridsuite/study/server/SupervisionController.java index 594760ab5..e58073fdc 100644 --- a/src/main/java/org/gridsuite/study/server/SupervisionController.java +++ b/src/main/java/org/gridsuite/study/server/SupervisionController.java @@ -95,11 +95,11 @@ public ResponseEntity getIndexedTombstonedEquipmentsCount() { return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(Long.toString(supervisionService.getIndexedTombstonedEquipmentsCount())); } - @DeleteMapping(value = "/studies/{studyUuid}/equipments/indexation") + @DeleteMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/equipments/indexation") @Operation(summary = "delete indexed equipments and tombstoned equipments for the given study") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "all indexed equipments and tombstoned equipments for the given study have been deleted")}) - public ResponseEntity deleteStudyIndexedEquipmentsAndTombstoned(@PathVariable("studyUuid") UUID studyUuid) { - return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(Long.toString(supervisionService.deleteStudyIndexedEquipmentsAndTombstoned(studyUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid)))); + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "all indexed equipments and tombstoned equipments for the given study for the given root network have been deleted")}) + public ResponseEntity deleteStudyIndexedEquipmentsAndTombstoned(@PathVariable("studyUuid") UUID studyUuid, @PathVariable("rootNetworkUuid") UUID rootNetworkUuid) { + return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(Long.toString(supervisionService.deleteStudyIndexedEquipmentsAndTombstoned(studyUuid, rootNetworkUuid))); } @GetMapping(value = "/orphan_indexed_network_uuids") diff --git a/src/main/java/org/gridsuite/study/server/service/NetworkConversionService.java b/src/main/java/org/gridsuite/study/server/service/NetworkConversionService.java index 5919e7f51..13e389e02 100644 --- a/src/main/java/org/gridsuite/study/server/service/NetworkConversionService.java +++ b/src/main/java/org/gridsuite/study/server/service/NetworkConversionService.java @@ -69,12 +69,17 @@ public void persistNetwork(UUID caseUuid, UUID studyUuid, UUID rootNetworkUuid, throw new UncheckedIOException(e); } - String path = UriComponentsBuilder.fromPath(DELIMITER + NETWORK_CONVERSION_API_VERSION + "/networks") - .queryParam(CASE_UUID, caseUuid) - .queryParam(QUERY_PARAM_VARIANT_ID, variantId) - .queryParam(REPORT_UUID, importReportUuid) - .queryParam(QUERY_PARAM_RECEIVER, receiver) - .queryParam(CASE_FORMAT, caseFormat) + UriComponentsBuilder builder = UriComponentsBuilder.fromPath(DELIMITER + NETWORK_CONVERSION_API_VERSION + "/networks") + .queryParam(CASE_UUID, caseUuid) + .queryParam(REPORT_UUID, importReportUuid) + .queryParam(QUERY_PARAM_RECEIVER, receiver) + .queryParam(CASE_FORMAT, caseFormat); + + if (variantId != null) { + builder.queryParam(QUERY_PARAM_VARIANT_ID, variantId); + } + + String path = builder .buildAndExpand() .toUriString(); diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index 09cd561ce..c628a6f66 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -385,8 +385,9 @@ public void duplicateStudyAsync(BasicStudyInfos basicStudyInfos, UUID sourceStud StudyEntity duplicatedStudy = duplicateStudy(basicStudyInfos, sourceStudyUuid, userId); - reindexStudy(duplicatedStudy, getStudyFirstRootNetworkUuid(duplicatedStudy.getId())); - + rootNetworkService.getStudyRootNetworks(duplicatedStudy.getId()).forEach(rootNetworkEntity -> { + reindexStudy(duplicatedStudy, rootNetworkEntity.getId()); + }); } catch (Exception e) { LOGGER.error(e.toString(), e); } finally { @@ -1762,6 +1763,7 @@ public void createModifications(UUID studyUuid, UUID nodeUuid, List modifi try { checkStudyContainsNode(studyUuid, nodeUuid); NetworkModificationNodeInfoEntity networkModificationNodeInfoEntity = networkModificationTreeService.getNetworkModificationNodeInfoEntity(nodeUuid); + //TODO : not ok, creating multiple times the same modification for each root network rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> { UUID rootNetworkUuid = rootNetworkEntity.getId(); RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoService.getRootNetworkNodeInfo(nodeUuid, rootNetworkUuid).orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); diff --git a/src/test/java/org/gridsuite/study/server/LoadFlowTest.java b/src/test/java/org/gridsuite/study/server/LoadFlowTest.java index eb6a9f076..c9b60d54b 100644 --- a/src/test/java/org/gridsuite/study/server/LoadFlowTest.java +++ b/src/test/java/org/gridsuite/study/server/LoadFlowTest.java @@ -808,7 +808,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); - rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyService.getStudyFirstRootNetworkUuid(studyUuid), + rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid), RootNetworkNodeInfo.builder().variantId(variantId).build()); return modificationNode; diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java index ab1016f35..f0352e6cf 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java @@ -211,7 +211,7 @@ class NetworkModificationTest { private RootNetworkNodeInfoService rootNetworkNodeInfoService; @Autowired - private StudyService studyService; + private StudyTestUtils studyTestUtils; //output destinations private static final String STUDY_UPDATE_DESTINATION = "study.update"; @@ -504,7 +504,7 @@ void testBuild() throws Exception { assertEquals(List.of(modificationGroupUuid1, modificationGroupUuid2, modificationGroupUuid3, modificationGroupUuid4, modificationGroupUuid5), buildInfos.getModificationGroupUuids()); // Mark the node 3 status as built - RootNetworkNodeInfoEntity rootNetworkNodeInfo3Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode3.getId(), studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfo3Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode3.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfo3Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILT)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo3Entity); @@ -515,17 +515,17 @@ void testBuild() throws Exception { assertEquals(List.of(modificationGroupUuid4), buildInfos.getModificationGroupUuids()); // Mark the node 2 status as not built - RootNetworkNodeInfoEntity rootNetworkNodeInfo2Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode2.getId(), studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfo2Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode2.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfo2Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.NOT_BUILT)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo2Entity); // Mark the node 4 status as not built - RootNetworkNodeInfoEntity rootNetworkNodeInfo4Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode4.getId(), studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfo4Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode4.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfo4Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.NOT_BUILT)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo4Entity); // Mark the node 5 status as built - RootNetworkNodeInfoEntity rootNetworkNodeInfo5Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode5.getId(), studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfo5Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode5.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfo5Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILT)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo5Entity); @@ -537,7 +537,7 @@ void testBuild() throws Exception { assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode5.getId(), rootNetworkUuid).getGlobalBuildStatus()); // Mark the node 3 status as built - rootNetworkNodeInfo3Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode3.getId(), studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + rootNetworkNodeInfo3Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode3.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfo3Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILT)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo3Entity); @@ -564,7 +564,7 @@ void testLocalBuildValue() throws Exception { wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); // Mark the node status as built - RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode.getId(), studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfoEntity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILT)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfoEntity); @@ -688,10 +688,10 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, bodyJson, NETWORK_UUID_STRING, VARIANT_ID_2); // test build status on switch modification - RootNetworkNodeInfoEntity rootNetworkNodeInfo1Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode1.getId(), studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfo1Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode1.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfo1Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILT)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo1Entity); - RootNetworkNodeInfoEntity rootNetworkNodeInfo2Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode2.getId(), studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfo2Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode2.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfo2Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILT)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo2Entity); @@ -1008,7 +1008,7 @@ void testCreateLine() throws Exception { + "\"voltageLevelId1\":\"idVL1\"," + "\"busOrBusbarSectionId1\":\"idBus1\"," + "\"voltageLevelId2\":\"idVL2\"," + "\"busOrBusbarSectionId2\":\"idBus2\"}"; // Mark the node 1 status as building - RootNetworkNodeInfoEntity rootNetworkNodeInfo1Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode1Uuid, studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfo1Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode1Uuid, studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfo1Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILDING)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo1Entity); // create line on building node @@ -1079,7 +1079,7 @@ void testCreateTwoWindingsTransformer() throws Exception { String createTwoWindingsTransformerAttributes2 = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId3\",\"equipmentName\":\"2wtName3\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; // Mark the node 1 status as building - RootNetworkNodeInfoEntity rootNetworkNodeInfo1Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode1Uuid, studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfo1Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode1Uuid, studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfo1Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILDING)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo1Entity); // create Two Windings Transformer on building node @@ -1347,7 +1347,7 @@ void testCreateLoad() throws Exception { String createLoadAttributes2 = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId3\",\"loadName\":\"loadName3\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; // Mark the node 3 status as built - RootNetworkNodeInfoEntity rootNetworkNodeInfo3Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode3Uuid, studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfo3Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode3Uuid, studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfo3Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILDING)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo3Entity); @@ -1536,7 +1536,7 @@ void testCreateSubstation() throws Exception { String createSubstationAttributes2 = "{\"type\":\"" + ModificationType.SUBSTATION_CREATION + "\",\"substationId\":\"substationId2\",\"substationName\":\"substationName2\",\"country\":\"AD\"}"; // Mark the node 1 status as built - RootNetworkNodeInfoEntity rootNetworkNodeInfo1Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode1Uuid, studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfo1Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode1Uuid, studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfo1Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILDING)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo1Entity); // create substation on building node @@ -1609,7 +1609,7 @@ void testCreateVoltageLevel() throws Exception { String createVoltageLevelAttributes2 = "{\"type\":\"" + ModificationType.VOLTAGE_LEVEL_CREATION + "\",\"voltageLevelId\":\"voltageLevelId3\",\"voltageLevelName\":\"voltageLevelName3\"" + ",\"nominalVoltage\":\"379.1\", \"substationId\":\"s2\"}"; // Mark the node 1 status as building - RootNetworkNodeInfoEntity rootNetworkNodeInfo1Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode1Uuid, studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfo1Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode1Uuid, studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfo1Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILDING)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo1Entity); // create voltage level on building node @@ -2072,7 +2072,7 @@ void testDuplicateModification() throws Exception { expectedBody); // now we do the same but on a built node - RootNetworkNodeInfoEntity rootNetworkNodeInfo1Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(nodeUuid1, studyService.getStudyFirstRootNetworkUuid(studyUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfo1Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(nodeUuid1, studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfo1Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILT)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo1Entity); @@ -2331,7 +2331,7 @@ void testNodesInvalidation(final MockWebServer server) throws Exception { NetworkModificationNode modificationNode3 = createNetworkModificationNode(studyNameUserIdUuid, modificationNode2Uuid, UUID.randomUUID(), VARIANT_ID_3, "node 3", BuildStatus.BUILT, userId); UUID modificationNode3Uuid = modificationNode3.getId(); - RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode1Uuid, studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode1Uuid, studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfoEntity.setSecurityAnalysisResultUuid(UUID.fromString(SECURITY_ANALYSIS_RESULT_UUID)); rootNetworkNodeInfoEntity.setSensitivityAnalysisResultUuid(UUID.fromString(SENSITIVITY_ANALYSIS_RESULT_UUID)); rootNetworkNodeInfoEntity.setNonEvacuatedEnergyResultUuid(UUID.fromString(SENSITIVITY_ANALYSIS_NON_EVACUATED_ENERGY_RESULT_UUID)); @@ -2373,7 +2373,7 @@ void testNodesInvalidation(final MockWebServer server) throws Exception { assertTrue(requests.stream().anyMatch(r -> r.getPath().matches("/v1/results/" + STATE_ESTIMATION_RESULT_UUID))); // Mark the node 3 status as built - RootNetworkNodeInfoEntity rootNetworkNodeInfo3Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode3Uuid, studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfo3Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode3Uuid, studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfo3Entity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILT)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfo3Entity); @@ -2406,7 +2406,7 @@ void testRemoveLoadFlowComputationReport(final MockWebServer server) throws Exce NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", BuildStatus.BUILT, userId); UUID modificationNode1Uuid = modificationNode1.getId(); // In this node, let's say we have all computations results - RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode1Uuid, studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode1Uuid, studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfoEntity.setLoadFlowResultUuid(LOADFLOW_RESULT_UUID); rootNetworkNodeInfoEntity.setSecurityAnalysisResultUuid(UUID.fromString(SECURITY_ANALYSIS_RESULT_UUID)); rootNetworkNodeInfoEntity.setSensitivityAnalysisResultUuid(UUID.fromString(SENSITIVITY_ANALYSIS_RESULT_UUID)); @@ -2489,7 +2489,7 @@ void testUpdateOfBuildStatus() throws Exception { wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING, VARIANT_ID); // Mark the node status as built - RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode.getId(), studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); rootNetworkNodeInfoEntity.setNodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.BUILT)); rootNetworkNodeInfoRepository.save(rootNetworkNodeInfoEntity); @@ -2858,7 +2858,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); - rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyService.getStudyFirstRootNetworkUuid(studyUuid), + rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid), RootNetworkNodeInfo.builder().variantId(variantId).nodeBuildStatus(NodeBuildStatus.from(buildStatus)).build()); return modificationNode; diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java index 724f271b8..a7c740441 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java @@ -995,7 +995,7 @@ private void createNode(UUID studyUuid, AbstractNode parentNode, NetworkModifica newNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); - rootNetworkNodeInfoService.updateRootNetworkNode(newNode.getId(), studyService.getStudyFirstRootNetworkUuid(studyUuid), + rootNetworkNodeInfoService.updateRootNetworkNode(newNode.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid), RootNetworkNodeInfo.builder() .variantId(newNode.getVariantId()) .nodeBuildStatus(newNode.getNodeBuildStatus()) @@ -1039,7 +1039,7 @@ private void insertNode(UUID studyUuid, AbstractNode parentNode, NetworkModifica newNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); - rootNetworkNodeInfoService.updateRootNetworkNode(newNode.getId(), studyService.getStudyFirstRootNetworkUuid(studyUuid), + rootNetworkNodeInfoService.updateRootNetworkNode(newNode.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid), RootNetworkNodeInfo.builder().variantId(variantId).nodeBuildStatus(newNode.getNodeBuildStatus()).build()); } diff --git a/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java b/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java index 36ab6b67c..5d19e35b9 100644 --- a/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java +++ b/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java @@ -532,7 +532,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); - rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyService.getStudyFirstRootNetworkUuid(studyUuid), + rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid), RootNetworkNodeInfo.builder().variantId(variantId).build()); return modificationNode; diff --git a/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java b/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java index e2f13aec2..cf11da990 100644 --- a/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java +++ b/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java @@ -629,7 +629,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); - rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyService.getStudyFirstRootNetworkUuid(studyUuid), + rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid), RootNetworkNodeInfo.builder().variantId(variantId).nodeBuildStatus(NodeBuildStatus.from(buildStatus)).build()); return modificationNode; diff --git a/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java b/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java index 1cab52715..28dcfb5e7 100644 --- a/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java +++ b/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java @@ -631,7 +631,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); - rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyService.getStudyFirstRootNetworkUuid(studyUuid), + rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid), RootNetworkNodeInfo.builder().variantId(variantId).build()); return modificationNode; diff --git a/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java b/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java index 416e1a80a..45d18c87b 100644 --- a/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java +++ b/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java @@ -873,7 +873,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); - rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyService.getStudyFirstRootNetworkUuid(studyUuid), + rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid), RootNetworkNodeInfo.builder().variantId(variantId).nodeBuildStatus(NodeBuildStatus.from(buildStatus)).build()); return modificationNode; diff --git a/src/test/java/org/gridsuite/study/server/SingleLineDiagramTest.java b/src/test/java/org/gridsuite/study/server/SingleLineDiagramTest.java index 5d82280c0..0a280aa4f 100644 --- a/src/test/java/org/gridsuite/study/server/SingleLineDiagramTest.java +++ b/src/test/java/org/gridsuite/study/server/SingleLineDiagramTest.java @@ -565,7 +565,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); - rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyService.getStudyFirstRootNetworkUuid(studyUuid), + rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid), RootNetworkNodeInfo.builder().variantId(variantId).nodeBuildStatus(NodeBuildStatus.from(buildStatus)).build()); return modificationNode; diff --git a/src/test/java/org/gridsuite/study/server/StateEstimationTest.java b/src/test/java/org/gridsuite/study/server/StateEstimationTest.java index a1597cb0c..de68c5ff3 100644 --- a/src/test/java/org/gridsuite/study/server/StateEstimationTest.java +++ b/src/test/java/org/gridsuite/study/server/StateEstimationTest.java @@ -268,7 +268,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); - rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyService.getStudyFirstRootNetworkUuid(studyUuid), + rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid), RootNetworkNodeInfo.builder().variantId(variantId).build()); return modificationNode; diff --git a/src/test/java/org/gridsuite/study/server/StudyControllerDynamicSimulationTest.java b/src/test/java/org/gridsuite/study/server/StudyControllerDynamicSimulationTest.java index 0ac11c7cc..d2ce0fc70 100644 --- a/src/test/java/org/gridsuite/study/server/StudyControllerDynamicSimulationTest.java +++ b/src/test/java/org/gridsuite/study/server/StudyControllerDynamicSimulationTest.java @@ -263,7 +263,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU UUID newNodeId = UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE))); modificationNode.setId(newNodeId); assertThat(mess.getHeaders()).containsEntry(NotificationService.HEADER_INSERT_MODE, InsertMode.CHILD.name()); - rootNetworkNodeInfoService.updateRootNetworkNode(newNodeId, studyService.getStudyFirstRootNetworkUuid(studyUuid), RootNetworkNodeInfo.builder().variantId(variantId).build()); + rootNetworkNodeInfoService.updateRootNetworkNode(newNodeId, studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid), RootNetworkNodeInfo.builder().variantId(variantId).build()); return modificationNode; } diff --git a/src/test/java/org/gridsuite/study/server/StudyTest.java b/src/test/java/org/gridsuite/study/server/StudyTest.java index 51867035c..ba109d0f8 100644 --- a/src/test/java/org/gridsuite/study/server/StudyTest.java +++ b/src/test/java/org/gridsuite/study/server/StudyTest.java @@ -816,7 +816,7 @@ void test(final MockWebServer server) throws Exception { mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/export-network/{format}?fileName=myFileName", studyNameUserIdUuid, firstRootNetworkUuid, modificationNode1Uuid, "XIIDM")) .andExpect(status().isInternalServerError()); - rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode1.getId(), studyService.getStudyFirstRootNetworkUuid(studyNameUserIdUuid), + rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode1.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid), RootNetworkNodeInfo.builder().nodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)).build()); mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/export-network/{format}?fileName=myFileName", @@ -1081,7 +1081,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); - rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyService.getStudyFirstRootNetworkUuid(studyUuid), + rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid), RootNetworkNodeInfo.builder().variantId(variantId).nodeBuildStatus(NodeBuildStatus.from(buildStatus)).build()); return modificationNode; @@ -1553,7 +1553,7 @@ private void testDuplicateStudy(final MockWebServer mockWebServer, UUID study1Uu checkElementUpdatedMessageSent(study1Uuid, userId); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); - rootNetworkNodeInfoService.updateRootNetworkNode(node2.getId(), studyService.getStudyFirstRootNetworkUuid(study1Uuid), + rootNetworkNodeInfoService.updateRootNetworkNode(node2.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid), RootNetworkNodeInfo.builder() .securityAnalysisResultUuid(UUID.randomUUID()) .sensitivityAnalysisResultUuid(UUID.randomUUID()) @@ -1791,7 +1791,7 @@ void testCutAndPasteNode(final MockWebServer mockWebServer) throws Exception { checkElementUpdatedMessageSent(study1Uuid, userId); wireMockUtils.verifyNetworkModificationPost(stubUuid, createLoadAttributes, NETWORK_UUID_STRING); - rootNetworkNodeInfoService.updateRootNetworkNode(node2.getId(), studyService.getStudyFirstRootNetworkUuid(study1Uuid), + rootNetworkNodeInfoService.updateRootNetworkNode(node2.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid), RootNetworkNodeInfo.builder() .loadFlowResultUuid(UUID.randomUUID()) .securityAnalysisResultUuid(UUID.randomUUID()) @@ -2118,7 +2118,7 @@ void testDuplicateNode(final MockWebServer mockWebServer) throws Exception { checkElementUpdatedMessageSent(study1Uuid, userId); wireMockUtils.verifyNetworkModificationPostWithVariant(stubUuid, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); - rootNetworkNodeInfoService.updateRootNetworkNode(node2.getId(), studyService.getStudyFirstRootNetworkUuid(study1Uuid), + rootNetworkNodeInfoService.updateRootNetworkNode(node2.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid), RootNetworkNodeInfo.builder() .loadFlowResultUuid(UUID.randomUUID()) .securityAnalysisResultUuid(UUID.randomUUID()) @@ -2185,7 +2185,7 @@ void testDuplicateNode(final MockWebServer mockWebServer) throws Exception { .andExpect(status().isForbidden()); // Test Built status when duplicating an empty node - UUID rootNetworkUuid = studyService.getStudyFirstRootNetworkUuid(study1Uuid); + UUID rootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid); assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(node3.getId(), rootNetworkUuid).getGlobalBuildStatus()); duplicateNode(study1Uuid, study1Uuid, emptyNode, node3.getId(), InsertMode.BEFORE, userId); assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(node3.getId(), rootNetworkUuid).getGlobalBuildStatus()); diff --git a/src/test/java/org/gridsuite/study/server/VoltageInitTest.java b/src/test/java/org/gridsuite/study/server/VoltageInitTest.java index 281ecbd48..e63d539d6 100644 --- a/src/test/java/org/gridsuite/study/server/VoltageInitTest.java +++ b/src/test/java/org/gridsuite/study/server/VoltageInitTest.java @@ -934,7 +934,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); - rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyService.getStudyFirstRootNetworkUuid(studyUuid), + rootNetworkNodeInfoService.updateRootNetworkNode(modificationNode.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid), RootNetworkNodeInfo.builder().variantId(variantId).nodeBuildStatus(NodeBuildStatus.from(buildStatus)).build()); return modificationNode; From 231a472b12b538e2ea750e0b0330ddc7311cf232 Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Wed, 18 Dec 2024 12:19:37 +0100 Subject: [PATCH 07/17] fix: notifications when creationg and updating root networks Signed-off-by: LE SAULNIER Kevin --- .../notification/NotificationService.java | 20 +++++++++++++++++++ .../study/server/service/ConsumerService.java | 9 +++++++-- .../study/server/service/StudyService.java | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/notification/NotificationService.java b/src/main/java/org/gridsuite/study/server/notification/NotificationService.java index 4eb906832..db78cbdd9 100644 --- a/src/main/java/org/gridsuite/study/server/notification/NotificationService.java +++ b/src/main/java/org/gridsuite/study/server/notification/NotificationService.java @@ -117,6 +117,9 @@ public class NotificationService { public static final String MESSAGE_LOG = "Sending message : {}"; public static final String DEFAULT_ERROR_MESSAGE = "Unknown error"; + public static final String ROOT_NETWORKS_UPDATED = "rootNetworksUpdated"; + public static final String ROOT_NETWORKS_UPDATE_FAILED = "rootNetworksUpdateFailed"; + public static final String STUDY_ALERT = "STUDY_ALERT"; private static final String CATEGORY_BROKER_OUTPUT = NotificationService.class.getName() + ".output-broker-messages"; @@ -427,4 +430,21 @@ public void emitStudyAlert(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, LOGGER.error("Unable to notify on study alert", e); } } + + @PostCompletion + public void emitRootNetworksUpdated(UUID studyUuid) { + sendUpdateMessage(MessageBuilder.withPayload("") + .setHeader(HEADER_STUDY_UUID, studyUuid) + .setHeader(HEADER_UPDATE_TYPE, ROOT_NETWORKS_UPDATED) + .build()); + } + + @PostCompletion + public void emitRootNetworksUpdateFailed(UUID studyUuid, String errorMessage) { + sendUpdateMessage(MessageBuilder.withPayload("") + .setHeader(HEADER_STUDY_UUID, studyUuid) + .setHeader(HEADER_UPDATE_TYPE, ROOT_NETWORKS_UPDATE_FAILED) + .setHeader(HEADER_ERROR, errorMessage) + .build()); + } } diff --git a/src/main/java/org/gridsuite/study/server/service/ConsumerService.java b/src/main/java/org/gridsuite/study/server/service/ConsumerService.java index 44fafc672..a735266ef 100644 --- a/src/main/java/org/gridsuite/study/server/service/ConsumerService.java +++ b/src/main/java/org/gridsuite/study/server/service/ConsumerService.java @@ -382,8 +382,13 @@ public Consumer> consumeCaseImportFailed() { UUID studyUuid = receiver.getStudyUuid(); String userId = receiver.getUserId(); - studyService.deleteStudyIfNotCreationInProgress(studyUuid, userId); - notificationService.emitStudyCreationError(studyUuid, userId, errorMessage); + switch(receiver.getCaseImportAction()) { + case STUDY_CREATION -> { + studyService.deleteStudyIfNotCreationInProgress(studyUuid, userId); + notificationService.emitStudyCreationError(studyUuid, userId, errorMessage); + } + case ROOT_NETWORK_CREATION, ROOT_NETWORK_MODIFICATION -> notificationService.emitRootNetworksUpdateFailed(studyUuid, errorMessage); + } } catch (Exception e) { LOGGER.error(e.toString(), e); } diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index c628a6f66..be7869883 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -310,10 +310,10 @@ public void createRootNetwork(@NonNull UUID studyUuid, @NonNull RootNetworkInfos if (rootNetworkCreationRequestEntityOpt.isPresent()) { rootNetworkService.createRootNetwork(studyEntity, rootNetworkInfos); rootNetworkService.deleteCreationRequest(rootNetworkCreationRequestEntityOpt.get()); - // TODO: send notification to frontend } else { rootNetworkService.delete(rootNetworkInfos); } + notificationService.emitRootNetworksUpdated(studyUuid); } @Transactional(readOnly = true) From 3c682ce23f3236f1437d87f813a84168aa3fb8d4 Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Mon, 23 Dec 2024 13:32:41 +0100 Subject: [PATCH 08/17] fix: getting tree is now linked to root network + fix apply modifications Signed-off-by: LE SAULNIER Kevin --- .../study/server/StudyController.java | 10 +-- .../MultipleNetworkModificationsInfos.java | 12 ++++ .../NetworkModificationContextInfos.java | 11 ++++ .../service/NetworkModificationService.java | 63 +++++++++++++++++++ .../NetworkModificationTreeService.java | 20 +++--- .../service/RootNetworkNodeInfoService.java | 8 +++ .../study/server/service/StudyService.java | 55 +++++++++++----- .../server/service/SupervisionService.java | 3 +- 8 files changed, 151 insertions(+), 31 deletions(-) create mode 100644 src/main/java/org/gridsuite/study/server/dto/modification/MultipleNetworkModificationsInfos.java create mode 100644 src/main/java/org/gridsuite/study/server/dto/modification/NetworkModificationContextInfos.java diff --git a/src/main/java/org/gridsuite/study/server/StudyController.java b/src/main/java/org/gridsuite/study/server/StudyController.java index 3d4b1084c..ae4c9de95 100644 --- a/src/main/java/org/gridsuite/study/server/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/StudyController.java @@ -1302,8 +1302,9 @@ public ResponseEntity restoreNodes(@Parameter(description = "study uuid") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "network modification tree"), @ApiResponse(responseCode = "404", description = "The study or the node not found")}) - public ResponseEntity getNetworkModificationTree(@Parameter(description = "study uuid") @PathVariable("studyUuid") UUID studyUuid) { - RootNode rootNode = networkModificationTreeService.getStudyTree(studyUuid); + public ResponseEntity getNetworkModificationTree(@Parameter(description = "study uuid") @PathVariable("studyUuid") UUID studyUuid, + @Parameter(description = "root network uuid") @RequestParam("rootNetworkUuid") UUID rootNetworkUuid) { + RootNode rootNode = networkModificationTreeService.getStudyTree(studyUuid, rootNetworkUuid); return rootNode != null ? ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(rootNode) : ResponseEntity.notFound().build(); @@ -1315,8 +1316,9 @@ public ResponseEntity getNetworkModificationTree(@Parameter(descriptio @ApiResponse(responseCode = "200", description = "network modification subtree"), @ApiResponse(responseCode = "404", description = "The study or the parent node not found")}) public ResponseEntity getNetworkModificationSubtree(@Parameter(description = "study uuid") @PathVariable("studyUuid") UUID studyUuid, - @Parameter(description = "parent node uuid") @RequestParam(value = "parentNodeUuid") UUID parentNodeUuid) { - NetworkModificationNode parentNode = (NetworkModificationNode) networkModificationTreeService.getStudySubtree(studyUuid, parentNodeUuid); + @Parameter(description = "parent node uuid") @RequestParam(value = "parentNodeUuid") UUID parentNodeUuid, + @Parameter(description = "root network uuid") @RequestParam(value = "rootNetworkUuid") UUID rootNetworkUuid) { + NetworkModificationNode parentNode = (NetworkModificationNode) networkModificationTreeService.getStudySubtree(studyUuid, parentNodeUuid, rootNetworkUuid); return parentNode != null ? ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(parentNode) : ResponseEntity.notFound().build(); diff --git a/src/main/java/org/gridsuite/study/server/dto/modification/MultipleNetworkModificationsInfos.java b/src/main/java/org/gridsuite/study/server/dto/modification/MultipleNetworkModificationsInfos.java new file mode 100644 index 000000000..2bf8db4a9 --- /dev/null +++ b/src/main/java/org/gridsuite/study/server/dto/modification/MultipleNetworkModificationsInfos.java @@ -0,0 +1,12 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.study.server.dto.modification; + +import java.util.List; +import java.util.UUID; + +public record MultipleNetworkModificationsInfos(List modificationsUuid, List networkModificationContextInfos) { } diff --git a/src/main/java/org/gridsuite/study/server/dto/modification/NetworkModificationContextInfos.java b/src/main/java/org/gridsuite/study/server/dto/modification/NetworkModificationContextInfos.java new file mode 100644 index 000000000..ed3cb7ef0 --- /dev/null +++ b/src/main/java/org/gridsuite/study/server/dto/modification/NetworkModificationContextInfos.java @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.study.server.dto.modification; + +import java.util.UUID; + +public record NetworkModificationContextInfos(UUID networkUuid, String variantId, UUID reportUuid, UUID nodeUuid) { } diff --git a/src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java b/src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java index eea9c7c52..23e074272 100644 --- a/src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java +++ b/src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java @@ -13,6 +13,7 @@ import org.gridsuite.study.server.RemoteServicesProperties; import org.gridsuite.study.server.dto.BuildInfos; import org.gridsuite.study.server.dto.NodeReceiver; +import org.gridsuite.study.server.dto.modification.MultipleNetworkModificationsInfos; import org.gridsuite.study.server.dto.modification.NetworkModificationResult; import org.gridsuite.study.server.networkmodificationtree.entities.NetworkModificationNodeInfoEntity; import org.gridsuite.study.server.networkmodificationtree.entities.RootNetworkNodeInfoEntity; @@ -419,4 +420,66 @@ public void deleteStashedModifications(UUID groupUUid) { throw handleHttpError(e, DELETE_NETWORK_MODIFICATION_FAILED); } } + + public Optional createModificationWithoutApplying(UUID studyUuid, + String createModificationAttributes, + UUID groupUuid) { + Optional result; + Objects.requireNonNull(studyUuid); + Objects.requireNonNull(createModificationAttributes); + + var uriComponentsBuilder = UriComponentsBuilder + .fromUriString(getNetworkModificationServerURI(false) + NETWORK_MODIFICATIONS_PATH) + .queryParam(GROUP_UUID, groupUuid); + + var path = uriComponentsBuilder + .buildAndExpand() + .toUriString(); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + + HttpEntity httpEntity = new HttpEntity<>(createModificationAttributes, headers); + + try { + result = restTemplate.exchange(path, HttpMethod.POST, httpEntity, + new ParameterizedTypeReference>() { + }).getBody(); + } catch (HttpStatusCodeException e) { + throw handleHttpError(e, CREATE_NETWORK_MODIFICATION_FAILED); + } + + return result; + } + + private HttpEntity getMultipleNetworkModificationInfosBody(MultipleNetworkModificationsInfos multipleNetworkModificationInfos) { + HttpEntity httpEntity; + try { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + httpEntity = new HttpEntity<>(objectMapper.writeValueAsString(multipleNetworkModificationInfos), headers); + } catch (JsonProcessingException e) { + throw new UncheckedIOException(e); + } + return httpEntity; + } + + public List> applyModifications(MultipleNetworkModificationsInfos multipleNetworkModificationInfos) { + List> result; + var path = UriComponentsBuilder.fromPath(NETWORK_MODIFICATIONS_PATH + "/apply"); + + HttpEntity httpEntity = getMultipleNetworkModificationInfosBody(multipleNetworkModificationInfos); + + try { + result = restTemplate.exchange( + getNetworkModificationServerURI(false) + path.buildAndExpand().toUriString(), + HttpMethod.POST, + httpEntity, + new ParameterizedTypeReference>>() { + }).getBody(); + } catch (HttpStatusCodeException e) { + throw handleHttpError(e, CREATE_NETWORK_MODIFICATION_FAILED); + } + return result; + } } diff --git a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java index 347722b55..4c50f92ed 100644 --- a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java +++ b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java @@ -337,17 +337,18 @@ public NodeEntity createRoot(StudyEntity study) { } @Transactional - public RootNode getStudyTree(UUID studyId) { + public RootNode getStudyTree(UUID studyId, UUID rootNetworkUuid) { NodeEntity rootNode = nodesRepository.findByStudyIdAndType(studyId, NodeType.ROOT).orElseThrow(() -> new StudyException(NODE_NOT_FOUND)); - RootNode studyTree = (RootNode) getStudySubtree(studyId, rootNode.getIdNode()); + RootNode studyTree = (RootNode) getStudySubtree(studyId, rootNode.getIdNode(), rootNetworkUuid); if (studyTree != null) { studyTree.setStudyId(studyId); } return studyTree; } - private void completeNodeInfos(List nodes, UUID studyUuid) { - RootNetworkEntity rootNetworkEntity = rootNetworkRepository.findAllByStudyId(studyUuid).stream().findFirst().orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); + private void completeNodeInfos(List nodes, UUID studyUuid, UUID rootNetworkUuid) { +// RootNetworkEntity rootNetworkEntity = rootNetworkRepository.findAllByStudyId(studyUuid).stream().findFirst().orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); + RootNetworkEntity rootNetworkEntity = rootNetworkService.getRootNetwork(rootNetworkUuid).orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); nodes.forEach(nodeInfo -> { if (nodeInfo instanceof RootNode rootNode) { rootNode.setReportUuid(rootNetworkEntity.getReportUuid()); @@ -358,7 +359,7 @@ private void completeNodeInfos(List nodes, UUID studyUuid) { } @Transactional - public AbstractNode getStudySubtree(UUID studyId, UUID parentNodeUuid) { + public AbstractNode getStudySubtree(UUID studyId, UUID parentNodeUuid, UUID rootNetworkUuid) { // TODO: not working because of proxy appearing in tests TOFIX later // List nodeUuids = nodesRepository.findAllDescendants(parentNodeUuid).stream().map(UUID::fromString).toList(); // List nodes = nodesRepository.findAllById(nodeUuids); @@ -367,7 +368,7 @@ public AbstractNode getStudySubtree(UUID studyId, UUID parentNodeUuid) { List allNodeInfos = new ArrayList<>(); repositories.forEach((key, repository) -> allNodeInfos.addAll(repository.getAll( nodes.stream().filter(n -> n.getType().equals(key)).map(NodeEntity::getIdNode).collect(Collectors.toSet())))); - completeNodeInfos(allNodeInfos, studyId); + completeNodeInfos(allNodeInfos, studyId, rootNetworkUuid); Map fullMap = allNodeInfos.stream().collect(Collectors.toMap(AbstractNode::getId, Function.identity())); nodes.stream() @@ -377,9 +378,9 @@ public AbstractNode getStudySubtree(UUID studyId, UUID parentNodeUuid) { } @Transactional - public void duplicateStudyNodes(StudyEntity studyEntity, UUID sourceStudyUuid) { + public void duplicateStudyNodes(StudyEntity studyEntity, UUID sourceStudyUuid, UUID rootNetworkUuid) { createRoot(studyEntity); - AbstractNode rootNode = getStudyTree(sourceStudyUuid); + AbstractNode rootNode = getStudyTree(sourceStudyUuid, rootNetworkUuid); cloneStudyTree(rootNode, null, studyEntity); } @@ -643,7 +644,8 @@ private void getBuildInfos(NodeEntity nodeEntity, UUID rootNetworkUuid, BuildInf AbstractNode node = repositories.get(nodeEntity.getType()).getNode(nodeEntity.getIdNode()); if (node.getType() == NodeType.NETWORK_MODIFICATION) { NetworkModificationNode modificationNode = (NetworkModificationNode) node; - if (!modificationNode.getNodeBuildStatus().isBuilt()) { + RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoService.getRootNetworkNodeInfo(nodeEntity.getIdNode(), rootNetworkUuid).orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); + if (!rootNetworkNodeInfoEntity.getNodeBuildStatus().toDto().isBuilt()) { UUID reportUuid = getModificationReportUuid(nodeEntity.getIdNode(), rootNetworkUuid, nodeToBuildUuid); buildInfos.insertModificationInfos(modificationNode.getModificationGroupUuid(), new ReportInfos(reportUuid, modificationNode.getId())); getBuildInfos(nodeEntity.getParentNode(), rootNetworkUuid, buildInfos, nodeToBuildUuid); diff --git a/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java b/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java index 6546a6ec1..0ed50daa0 100644 --- a/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java +++ b/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java @@ -12,6 +12,7 @@ import org.gridsuite.study.server.StudyException; import org.gridsuite.study.server.dto.*; import org.gridsuite.study.server.dto.dynamicsimulation.DynamicSimulationStatus; +import org.gridsuite.study.server.dto.modification.NetworkModificationContextInfos; import org.gridsuite.study.server.dto.sensianalysis.SensitivityAnalysisCsvFileInfos; import org.gridsuite.study.server.dto.timeseries.TimeSeriesMetadataInfos; import org.gridsuite.study.server.dto.timeseries.TimelineEventInfos; @@ -407,6 +408,13 @@ public List> getDeleteRootNetworkNodeInfosFutures(List new StudyException(ROOT_NETWORK_NOT_FOUND)); + String variantId = rootNetworkNodeInfoEntity.getVariantId(); + UUID reportUuid = rootNetworkNodeInfoEntity.getModificationReports().get(nodeUuid); + return new NetworkModificationContextInfos(networkUuid, variantId, reportUuid, nodeUuid); + } + private List getReportUuids(RootNetworkNodeInfo rootNetworkNodeInfo) { return Stream.of( rootNetworkNodeInfo.getModificationReports().values().stream(), diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index be7869883..f6c25e560 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -22,6 +22,8 @@ import org.gridsuite.study.server.dto.dynamicsimulation.event.EventInfos; import org.gridsuite.study.server.dto.elasticsearch.EquipmentInfos; import org.gridsuite.study.server.dto.impacts.SimpleElementImpact; +import org.gridsuite.study.server.dto.modification.MultipleNetworkModificationsInfos; +import org.gridsuite.study.server.dto.modification.NetworkModificationContextInfos; import org.gridsuite.study.server.dto.modification.NetworkModificationResult; import org.gridsuite.study.server.dto.nonevacuatedenergy.*; import org.gridsuite.study.server.dto.voltageinit.parameters.StudyVoltageInitParameters; @@ -56,12 +58,14 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.HttpStatusCodeException; +import javax.swing.text.html.Option; import java.io.UncheckedIOException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -542,7 +546,8 @@ private StudyEntity duplicateStudy(BasicStudyInfos studyInfos, UUID sourceStudyU StudyEntity sourceStudy = studyRepository.findById(sourceStudyUuid).orElseThrow(() -> new StudyException(STUDY_NOT_FOUND)); StudyEntity newStudyEntity = duplicateStudyEntity(sourceStudy, studyInfos.getId()); - networkModificationTreeService.duplicateStudyNodes(newStudyEntity, sourceStudyUuid); + //TODO: to fix, should not have any root network UUID here + networkModificationTreeService.duplicateStudyNodes(newStudyEntity, sourceStudyUuid, self.getStudyFirstRootNetworkUuid(sourceStudyUuid)); rootNetworkService.duplicateStudyRootNetworks(newStudyEntity, sourceStudyUuid); UUID sourceStudyFirstRootNetworkUuid = self.getStudyFirstRootNetworkUuid(newStudyEntity.getId()); @@ -1301,16 +1306,36 @@ public void createNetworkModification(UUID studyUuid, String createModificationA List childrenUuids = networkModificationTreeService.getChildren(nodeUuid); notificationService.emitStartModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids, NotificationService.MODIFICATIONS_CREATING_IN_PROGRESS); try { - rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> { - UUID rootNetworkUuid = rootNetworkEntity.getId(); - RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoService.getRootNetworkNodeInfo(nodeUuid, rootNetworkUuid).orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); - UUID groupUuid = networkModificationTreeService.getModificationGroupUuid(nodeUuid); - String variantId = rootNetworkNodeInfoEntity.getVariantId(); - UUID reportUuid = rootNetworkNodeInfoEntity.getModificationReports().get(nodeUuid); - - Optional networkModificationResult = networkModificationService.createModification(studyUuid, createModificationAttributes, groupUuid, variantId, reportUuid, nodeUuid, rootNetworkUuid); - updateNode(studyUuid, nodeUuid, rootNetworkUuid, networkModificationResult); - }); + List> networkModificationResults = null; + UUID groupUuid = networkModificationTreeService.getModificationGroupUuid(nodeUuid); + List studyRootNetworkEntities = rootNetworkService.getStudyRootNetworks(studyUuid); + + /* + * temporary solution - there is no way to create a modification and to apply it to several network contexts + * - we create a modification without applying it - we get its UUID + * - we apply this modification to multiple network context - we get a list of NetworkModificationResults + */ + // Create modification in networkModificationServer without applying it, and getting it's UUID + Optional modificationUuid = networkModificationService.createModificationWithoutApplying(studyUuid, createModificationAttributes, groupUuid); + if (modificationUuid.isPresent()) { + // if creating is successful, applying this modification to all root network contexts - each network context will generate a NetworkModificationResult + networkModificationResults = networkModificationService.applyModifications(new MultipleNetworkModificationsInfos( + List.of(modificationUuid.get()), + studyRootNetworkEntities.stream().map(rootNetworkEntity -> rootNetworkNodeInfoService.getNetworkModificationContextInfos(rootNetworkEntity.getId(), nodeUuid, rootNetworkEntity.getNetworkUuid()) + ).toList())); + } + if (networkModificationResults != null) { + int index = 0; + // for each NetworkModificationResult, send an impact notification - studyRootNetworkEntities are ordered in the same way as networkModificationResults + for (Optional modificationResultOpt : networkModificationResults) { + if (modificationResultOpt.isPresent() && studyRootNetworkEntities.get(index) != null) { + emitNetworkModificationImpacts(studyUuid, nodeUuid, studyRootNetworkEntities.get(index).getId(), modificationResultOpt.get()); + } + index++; + } + } + // invalidate all nodeUuid children + updateStatuses(studyUuid, nodeUuid); } finally { notificationService.emitEndModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids); } @@ -1434,7 +1459,8 @@ public void duplicateStudySubtree(UUID sourceStudyUuid, UUID targetStudyUuid, UU checkStudyContainsNode(targetStudyUuid, referenceNodeUuid); StudyEntity studyEntity = studyRepository.findById(targetStudyUuid).orElseThrow(() -> new StudyException(STUDY_NOT_FOUND)); - AbstractNode studySubTree = networkModificationTreeService.getStudySubtree(sourceStudyUuid, parentNodeToCopyUuid); + //TODO: tofix, should not have rootNetworkUuid here, but this method returns data linked to a specific root network + AbstractNode studySubTree = networkModificationTreeService.getStudySubtree(sourceStudyUuid, parentNodeToCopyUuid, getStudyFirstRootNetworkUuid(sourceStudyUuid)); UUID duplicatedNodeUuid = networkModificationTreeService.cloneStudyTree(studySubTree, referenceNodeUuid, studyEntity); notificationService.emitSubtreeInserted(targetStudyUuid, duplicatedNodeUuid, referenceNodeUuid); notificationService.emitElementUpdated(targetStudyUuid, userId); @@ -1858,11 +1884,6 @@ private List nodesTree(UUID nodeUuid) { return nodeIds; } - private void updateNode(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, Optional networkModificationResult) { - networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, nodeUuid, rootNetworkUuid, modificationResult)); - updateStatuses(studyUuid, nodeUuid); - } - private void emitNetworkModificationImpacts(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, NetworkModificationResult networkModificationResult) { //TODO move this / rename parent method when refactoring notifications networkModificationTreeService.updateNodeBuildStatus(nodeUuid, rootNetworkUuid, diff --git a/src/main/java/org/gridsuite/study/server/service/SupervisionService.java b/src/main/java/org/gridsuite/study/server/service/SupervisionService.java index 161578383..bce3eed65 100644 --- a/src/main/java/org/gridsuite/study/server/service/SupervisionService.java +++ b/src/main/java/org/gridsuite/study/server/service/SupervisionService.java @@ -300,7 +300,8 @@ private Integer deleteStateEstimationResults() { public void invalidateAllNodesBuilds(UUID studyUuid) { AtomicReference startTime = new AtomicReference<>(); startTime.set(System.nanoTime()); - RootNode rootNode = networkModificationTreeService.getStudyTree(studyUuid); + //TODO: to fix, should not have any root network uuid here + RootNode rootNode = networkModificationTreeService.getStudyTree(studyUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid)); //TODO: to parallelize ? rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> studyService.invalidateBuild(studyUuid, rootNode.getId(), rootNetworkEntity.getId(), false, false, true) From b4c9c4e77ef5bcfa684fa9d8decc7c97fe7b400b Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Mon, 23 Dec 2024 16:03:39 +0100 Subject: [PATCH 09/17] fix: getNode uses rootNetworkUuid to get build status Signed-off-by: LE SAULNIER Kevin --- .../java/org/gridsuite/study/server/StudyController.java | 5 +++-- .../NetworkModificationNodeInfoRepositoryProxy.java | 2 -- .../server/service/NetworkModificationTreeService.java | 8 ++++---- .../org/gridsuite/study/server/service/StudyService.java | 4 ++-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/StudyController.java b/src/main/java/org/gridsuite/study/server/StudyController.java index ae4c9de95..e44706835 100644 --- a/src/main/java/org/gridsuite/study/server/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/StudyController.java @@ -1342,8 +1342,9 @@ public ResponseEntity updateNode(@RequestBody NetworkModificationNode node @ApiResponse(responseCode = "200", description = "simplified nodes (without children"), @ApiResponse(responseCode = "404", description = "The study or the node not found")}) public ResponseEntity getNode(@Parameter(description = "study uuid") @PathVariable("studyUuid") UUID studyUuid, - @Parameter(description = "node uuid") @PathVariable("id") UUID nodeId) { - AbstractNode node = networkModificationTreeService.getNode(nodeId); + @Parameter(description = "node uuid") @PathVariable("id") UUID nodeId, + @Parameter(description = "root network uuid") @RequestParam("rootNetworkUuid") UUID rootNetworkUuid) { + AbstractNode node = networkModificationTreeService.getNode(nodeId, rootNetworkUuid); return node != null ? ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(node) : ResponseEntity.notFound().build(); diff --git a/src/main/java/org/gridsuite/study/server/networkmodificationtree/NetworkModificationNodeInfoRepositoryProxy.java b/src/main/java/org/gridsuite/study/server/networkmodificationtree/NetworkModificationNodeInfoRepositoryProxy.java index 534905a25..8978e8031 100644 --- a/src/main/java/org/gridsuite/study/server/networkmodificationtree/NetworkModificationNodeInfoRepositoryProxy.java +++ b/src/main/java/org/gridsuite/study/server/networkmodificationtree/NetworkModificationNodeInfoRepositoryProxy.java @@ -23,9 +23,7 @@ public NetworkModificationNodeInfoRepositoryProxy(NetworkModificationNodeInfoRep @Override public NetworkModificationNode toDto(NetworkModificationNodeInfoEntity node) { @SuppressWarnings("unused") - RootNetworkNodeInfoEntity rootNetworkNodeStatusEntity = node.getFirstRootNetworkNodeInfosEntity(); NetworkModificationNode networkModificationNode = NetworkModificationNode.builder().modificationGroupUuid(node.getModificationGroupUuid()).build(); - networkModificationNode.completeDtoFromRootNetworkNodeInfo(rootNetworkNodeStatusEntity); return completeNodeInfo(node, networkModificationNode); } } diff --git a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java index 4c50f92ed..c8f3d60c2 100644 --- a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java +++ b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java @@ -346,8 +346,7 @@ public RootNode getStudyTree(UUID studyId, UUID rootNetworkUuid) { return studyTree; } - private void completeNodeInfos(List nodes, UUID studyUuid, UUID rootNetworkUuid) { -// RootNetworkEntity rootNetworkEntity = rootNetworkRepository.findAllByStudyId(studyUuid).stream().findFirst().orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); + private void completeNodeInfos(List nodes, UUID rootNetworkUuid) { RootNetworkEntity rootNetworkEntity = rootNetworkService.getRootNetwork(rootNetworkUuid).orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); nodes.forEach(nodeInfo -> { if (nodeInfo instanceof RootNode rootNode) { @@ -368,7 +367,7 @@ public AbstractNode getStudySubtree(UUID studyId, UUID parentNodeUuid, UUID root List allNodeInfos = new ArrayList<>(); repositories.forEach((key, repository) -> allNodeInfos.addAll(repository.getAll( nodes.stream().filter(n -> n.getType().equals(key)).map(NodeEntity::getIdNode).collect(Collectors.toSet())))); - completeNodeInfos(allNodeInfos, studyId, rootNetworkUuid); + completeNodeInfos(allNodeInfos, rootNetworkUuid); Map fullMap = allNodeInfos.stream().collect(Collectors.toMap(AbstractNode::getId, Function.identity())); nodes.stream() @@ -464,9 +463,10 @@ private AbstractNode getSimpleNode(UUID nodeId) { } @Transactional - public AbstractNode getNode(UUID nodeId) { + public AbstractNode getNode(UUID nodeId, UUID rootNetworkUuid) { AbstractNode node = getSimpleNode(nodeId); nodesRepository.findAllByParentNodeIdNode(node.getId()).stream().map(NodeEntity::getIdNode).forEach(node.getChildrenIds()::add); + completeNodeInfos(List.of(node), rootNetworkUuid); return node; } diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index f6c25e560..38b5d3eb8 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -546,7 +546,7 @@ private StudyEntity duplicateStudy(BasicStudyInfos studyInfos, UUID sourceStudyU StudyEntity sourceStudy = studyRepository.findById(sourceStudyUuid).orElseThrow(() -> new StudyException(STUDY_NOT_FOUND)); StudyEntity newStudyEntity = duplicateStudyEntity(sourceStudy, studyInfos.getId()); - //TODO: to fix, should not have any root network UUID here + //TODO: to fix, should not have any root network UUID here - necessary because getStudyTree needs rootNetworkUUID for now to get all nodes status networkModificationTreeService.duplicateStudyNodes(newStudyEntity, sourceStudyUuid, self.getStudyFirstRootNetworkUuid(sourceStudyUuid)); rootNetworkService.duplicateStudyRootNetworks(newStudyEntity, sourceStudyUuid); @@ -1832,7 +1832,7 @@ public List getParentNodesReportLogs(UUID nodeUuid, UUID rootNetworkU @Transactional(readOnly = true) public List getParentNodesReport(UUID nodeUuid, UUID rootNetworkUuid, boolean nodeOnlyReport, ReportType reportType, Set severityLevels) { - AbstractNode nodeInfos = networkModificationTreeService.getNode(nodeUuid); + AbstractNode nodeInfos = networkModificationTreeService.getNode(nodeUuid, rootNetworkUuid); if (isNonRootNodeWithComputationReportType(nodeInfos, reportType)) { UUID reportUuid = getReportUuidForNode(nodeUuid, rootNetworkUuid, reportType); From d5a1d36a9ae4abf341f52986e8c77de0c794cc59 Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Fri, 3 Jan 2025 08:51:11 +0100 Subject: [PATCH 10/17] fix: modification duplication + report endpoint Signed-off-by: LE SAULNIER Kevin --- .../study/server/StudyController.java | 5 ++- .../service/NetworkModificationService.java | 13 ++++++++ .../study/server/service/StudyService.java | 31 ++++++++++++------- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/StudyController.java b/src/main/java/org/gridsuite/study/server/StudyController.java index 1760ef643..7ac97b512 100644 --- a/src/main/java/org/gridsuite/study/server/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/StudyController.java @@ -1102,15 +1102,17 @@ public ResponseEntity> getParentNodesReport(@Parameter(description return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getParentNodesReport(nodeUuid, rootNetworkUuid, nodeOnlyReport, reportType, severityLevels)); } - @GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/report/{reportId}/logs", produces = MediaType.APPLICATION_JSON_VALUE) + @GetMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/report/{reportId}/logs", produces = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Get node report logs") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The node report logs"), @ApiResponse(responseCode = "404", description = "The study/node is not found")}) public ResponseEntity> getNodeReportLogs(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid, + @Parameter(description = "root network id") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid, @Parameter(description = "node id") @PathVariable("nodeUuid") UUID nodeUuid, @Parameter(description = "reportId") @PathVariable("reportId") String reportId, @Parameter(description = "the message filter") @RequestParam(name = "message", required = false) String messageFilter, @Parameter(description = "Severity levels filter") @RequestParam(name = "severityLevels", required = false) Set severityLevels) { studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid); + rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkUuid); return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getReportLogs(reportId, messageFilter, severityLevels)); } @@ -1123,6 +1125,7 @@ public ResponseEntity> getParentNodesReportLogs(@Parameter(descr @Parameter(description = "the message filter") @RequestParam(name = "message", required = false) String messageFilter, @Parameter(description = "Severity levels filter") @RequestParam(name = "severityLevels", required = false) Set severityLevels) { studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid); + rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkUuid); return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getParentNodesReportLogs(nodeUuid, rootNetworkUuid, messageFilter, severityLevels)); } diff --git a/src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java b/src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java index 23e074272..b4ca5b7a0 100644 --- a/src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java +++ b/src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java @@ -358,6 +358,19 @@ public Optional createModifications(List modifi }).getBody(); } + public List handleNetworkModificationsWithoutApplying(List modificationUuidList, NetworkModificationNodeInfoEntity networkModificationNodeInfoEntity, ModificationsActionType action) { + var path = UriComponentsBuilder.fromPath(GROUP_PATH) + .queryParam(QUERY_PARAM_ACTION, action.name()); + + HttpEntity httpEntity = getModificationsUuidBody(modificationUuidList); + return restTemplate.exchange( + getNetworkModificationServerURI(false) + path.buildAndExpand(networkModificationNodeInfoEntity.getModificationGroupUuid()).toUriString(), + HttpMethod.PUT, + httpEntity, + new ParameterizedTypeReference>() { + }).getBody(); + } + public void createModifications(UUID sourceGroupUuid, UUID groupUuid) { Objects.requireNonNull(groupUuid); Objects.requireNonNull(sourceGroupUuid); diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index 4111fa06d..1211ef7c1 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -1825,17 +1825,26 @@ public void createModifications(UUID studyUuid, UUID nodeUuid, List modifi try { checkStudyContainsNode(studyUuid, nodeUuid); NetworkModificationNodeInfoEntity networkModificationNodeInfoEntity = networkModificationTreeService.getNetworkModificationNodeInfoEntity(nodeUuid); - //TODO : not ok, creating multiple times the same modification for each root network - rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> { - UUID rootNetworkUuid = rootNetworkEntity.getId(); - RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoService.getRootNetworkNodeInfo(nodeUuid, rootNetworkUuid).orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)); - UUID networkUuid = rootNetworkService.getNetworkUuid(rootNetworkUuid); - Optional networkModificationResult = networkModificationService.createModifications(modificationUuidList, networkUuid, networkModificationNodeInfoEntity, rootNetworkNodeInfoEntity, action); - // invalidate the whole subtree except the target node (we have built this node during the duplication) - networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, nodeUuid, rootNetworkUuid, modificationResult)); - }); - //TODO: NOT WORKING WELL, NOTIF HAS TO TARGET ROOT NETWORK UUID - updateStatuses(studyUuid, nodeUuid, true, true, true); + List studyRootNetworkEntities = rootNetworkService.getStudyRootNetworks(studyUuid); + List updatedModificationUuidList = networkModificationService.handleNetworkModificationsWithoutApplying(modificationUuidList, networkModificationNodeInfoEntity, action); + + List> networkModificationResults = networkModificationService.applyModifications(new MultipleNetworkModificationsInfos( + updatedModificationUuidList, + studyRootNetworkEntities.stream().map(rootNetworkEntity -> rootNetworkNodeInfoService.getNetworkModificationContextInfos(rootNetworkEntity.getId(), nodeUuid, rootNetworkEntity.getNetworkUuid()) + ).toList())); + + if (networkModificationResults != null) { + int index = 0; + // for each NetworkModificationResult, send an impact notification - studyRootNetworkEntities are ordered in the same way as networkModificationResults + for (Optional modificationResultOpt : networkModificationResults) { + if (modificationResultOpt.isPresent() && studyRootNetworkEntities.get(index) != null) { + emitNetworkModificationImpacts(studyUuid, nodeUuid, studyRootNetworkEntities.get(index).getId(), modificationResultOpt.get()); + } + index++; + } + } + // invalidate all nodeUuid children + updateStatuses(studyUuid, nodeUuid); } finally { notificationService.emitEndModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids); } From 72acaf28d99f3a8703101e20b7c9c247e2338eed Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Fri, 3 Jan 2025 15:32:17 +0100 Subject: [PATCH 11/17] fix: now able to remove multiple root networks at once Signed-off-by: LE SAULNIER Kevin --- .../java/org/gridsuite/study/server/StudyController.java | 6 +++--- .../org/gridsuite/study/server/service/StudyService.java | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/StudyController.java b/src/main/java/org/gridsuite/study/server/StudyController.java index 7ac97b512..b38298c68 100644 --- a/src/main/java/org/gridsuite/study/server/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/StudyController.java @@ -210,13 +210,13 @@ public ResponseEntity updateRootNetworkCase(@PathVariable("studyUuid") UUI return ResponseEntity.ok().build(); } - @DeleteMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}") + @DeleteMapping(value = "/studies/{studyUuid}/root-networks") @Operation(summary = "Create root network for study") @ApiResponse(responseCode = "200", description = "Root network created") public ResponseEntity deleteRootNetwork(@PathVariable("studyUuid") UUID studyUuid, - @PathVariable("rootNetworkUuid") UUID rootNetworkUuid, + @RequestBody List rootNetworkUuids, @RequestHeader(HEADER_USER_ID) String userId) { - studyService.deleteRootNetwork(studyUuid, rootNetworkUuid, userId); + studyService.deleteRootNetwork(studyUuid, rootNetworkUuids, userId); return ResponseEntity.ok().build(); } diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index 1211ef7c1..cebd4530a 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -286,11 +286,13 @@ public BasicStudyInfos createStudy(UUID caseUuid, String userId, UUID studyUuid, } @Transactional - public void deleteRootNetwork(UUID studyUuid, UUID rootNetworkUuid, String userId) { + public void deleteRootNetwork(UUID studyUuid, List rootNetworkUuids, String userId) { assertIsStudyExist(studyUuid); - rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkUuid); + rootNetworkUuids.forEach(rootNetworkUuid -> { + rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkUuid); - rootNetworkService.delete(rootNetworkUuid); + rootNetworkService.delete(rootNetworkUuid); + }); } @Transactional From 29784cb71dc2cc587523476ce0d7109c7c305bf3 Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Fri, 3 Jan 2025 15:44:39 +0100 Subject: [PATCH 12/17] fix: root network deletion does not break cases anymore Signed-off-by: LE SAULNIER Kevin --- .../java/org/gridsuite/study/server/StudyController.java | 2 +- .../org/gridsuite/study/server/service/StudyService.java | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/StudyController.java b/src/main/java/org/gridsuite/study/server/StudyController.java index b38298c68..55cb90af3 100644 --- a/src/main/java/org/gridsuite/study/server/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/StudyController.java @@ -216,7 +216,7 @@ public ResponseEntity updateRootNetworkCase(@PathVariable("studyUuid") UUI public ResponseEntity deleteRootNetwork(@PathVariable("studyUuid") UUID studyUuid, @RequestBody List rootNetworkUuids, @RequestHeader(HEADER_USER_ID) String userId) { - studyService.deleteRootNetwork(studyUuid, rootNetworkUuids, userId); + studyService.deleteRootNetworks(studyUuid, rootNetworkUuids, userId); return ResponseEntity.ok().build(); } diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index cebd4530a..1e913886f 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -23,7 +23,6 @@ import org.gridsuite.study.server.dto.elasticsearch.EquipmentInfos; import org.gridsuite.study.server.dto.impacts.SimpleElementImpact; import org.gridsuite.study.server.dto.modification.MultipleNetworkModificationsInfos; -import org.gridsuite.study.server.dto.modification.NetworkModificationContextInfos; import org.gridsuite.study.server.dto.modification.NetworkModificationResult; import org.gridsuite.study.server.dto.nonevacuatedenergy.*; import org.gridsuite.study.server.dto.voltageinit.parameters.StudyVoltageInitParameters; @@ -58,14 +57,12 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.HttpStatusCodeException; -import javax.swing.text.html.Option; import java.io.UncheckedIOException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -286,7 +283,7 @@ public BasicStudyInfos createStudy(UUID caseUuid, String userId, UUID studyUuid, } @Transactional - public void deleteRootNetwork(UUID studyUuid, List rootNetworkUuids, String userId) { + public void deleteRootNetworks(UUID studyUuid, List rootNetworkUuids, String userId) { assertIsStudyExist(studyUuid); rootNetworkUuids.forEach(rootNetworkUuid -> { rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkUuid); @@ -302,8 +299,9 @@ public RootNetworkCreationRequestInfos createRootNetworkRequest(UUID studyUuid, UUID importReportUuid = UUID.randomUUID(); UUID rootNetworkUuid = UUID.randomUUID(); RootNetworkCreationRequestEntity rootNetworkCreationRequestEntity = rootNetworkService.insertCreationRequest(rootNetworkUuid, studyEntity, userId); + UUID clonedCaseUuid = caseService.duplicateCase(caseUuid, true); try { - networkConversionService.persistNetwork(caseUuid, studyUuid, rootNetworkUuid, null, userId, importReportUuid, caseFormat, importParameters, CaseImportAction.ROOT_NETWORK_CREATION); + networkConversionService.persistNetwork(clonedCaseUuid, studyUuid, rootNetworkUuid, null, userId, importReportUuid, caseFormat, importParameters, CaseImportAction.ROOT_NETWORK_CREATION); } catch (Exception e) { rootNetworkService.deleteCreationRequest(rootNetworkCreationRequestEntity); throw new StudyException(ROOT_NETWORK_CREATION_FAILED); From 9536b46b10569992416960012676336a2ce36ae3 Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Fri, 3 Jan 2025 16:55:19 +0100 Subject: [PATCH 13/17] fix: send notification on root network deletion + improve code Signed-off-by: LE SAULNIER Kevin --- .../server/service/NetworkModificationTreeService.java | 4 +++- .../org/gridsuite/study/server/service/StudyService.java | 6 +++--- .../gridsuite/study/server/service/SupervisionService.java | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java index 86da705ba..462ace3c4 100644 --- a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java +++ b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java @@ -367,7 +367,9 @@ public AbstractNode getStudySubtree(UUID studyId, UUID parentNodeUuid, UUID root List allNodeInfos = new ArrayList<>(); repositories.forEach((key, repository) -> allNodeInfos.addAll(repository.getAll( nodes.stream().filter(n -> n.getType().equals(key)).map(NodeEntity::getIdNode).collect(Collectors.toSet())))); - completeNodeInfos(allNodeInfos, rootNetworkUuid); + if (rootNetworkUuid != null) { + completeNodeInfos(allNodeInfos, rootNetworkUuid); + } Map fullMap = allNodeInfos.stream().collect(Collectors.toMap(AbstractNode::getId, Function.identity())); nodes.stream() diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index 1e913886f..43c346050 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -290,6 +290,7 @@ public void deleteRootNetworks(UUID studyUuid, List rootNetworkUuids, Stri rootNetworkService.delete(rootNetworkUuid); }); + notificationService.emitRootNetworksUpdated(studyUuid); } @Transactional @@ -552,8 +553,7 @@ private StudyEntity duplicateStudy(BasicStudyInfos studyInfos, UUID sourceStudyU StudyEntity sourceStudy = studyRepository.findById(sourceStudyUuid).orElseThrow(() -> new StudyException(STUDY_NOT_FOUND)); StudyEntity newStudyEntity = duplicateStudyEntity(sourceStudy, studyInfos.getId()); - //TODO: to fix, should not have any root network UUID here - necessary because getStudyTree needs rootNetworkUUID for now to get all nodes status - networkModificationTreeService.duplicateStudyNodes(newStudyEntity, sourceStudyUuid, self.getStudyFirstRootNetworkUuid(sourceStudyUuid)); + networkModificationTreeService.duplicateStudyNodes(newStudyEntity, sourceStudyUuid, null); rootNetworkService.duplicateStudyRootNetworks(newStudyEntity, sourceStudyUuid); UUID sourceStudyFirstRootNetworkUuid = self.getStudyFirstRootNetworkUuid(newStudyEntity.getId()); @@ -1496,7 +1496,7 @@ public void duplicateStudySubtree(UUID sourceStudyUuid, UUID targetStudyUuid, UU StudyEntity studyEntity = studyRepository.findById(targetStudyUuid).orElseThrow(() -> new StudyException(STUDY_NOT_FOUND)); //TODO: tofix, should not have rootNetworkUuid here, but this method returns data linked to a specific root network - AbstractNode studySubTree = networkModificationTreeService.getStudySubtree(sourceStudyUuid, parentNodeToCopyUuid, getStudyFirstRootNetworkUuid(sourceStudyUuid)); + AbstractNode studySubTree = networkModificationTreeService.getStudySubtree(sourceStudyUuid, parentNodeToCopyUuid, null); UUID duplicatedNodeUuid = networkModificationTreeService.cloneStudyTree(studySubTree, referenceNodeUuid, studyEntity); notificationService.emitSubtreeInserted(targetStudyUuid, duplicatedNodeUuid, referenceNodeUuid); notificationService.emitElementUpdated(targetStudyUuid, userId); diff --git a/src/main/java/org/gridsuite/study/server/service/SupervisionService.java b/src/main/java/org/gridsuite/study/server/service/SupervisionService.java index bce3eed65..2d0d260d3 100644 --- a/src/main/java/org/gridsuite/study/server/service/SupervisionService.java +++ b/src/main/java/org/gridsuite/study/server/service/SupervisionService.java @@ -301,10 +301,10 @@ public void invalidateAllNodesBuilds(UUID studyUuid) { AtomicReference startTime = new AtomicReference<>(); startTime.set(System.nanoTime()); //TODO: to fix, should not have any root network uuid here - RootNode rootNode = networkModificationTreeService.getStudyTree(studyUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid)); + UUID rootNodeUuid = networkModificationTreeService.getStudyRootNodeUuid(studyUuid); //TODO: to parallelize ? rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> - studyService.invalidateBuild(studyUuid, rootNode.getId(), rootNetworkEntity.getId(), false, false, true) + studyService.invalidateBuild(studyUuid, rootNodeUuid, rootNetworkEntity.getId(), false, false, true) ); LOGGER.trace("Nodes builds deletion for study {} in : {} seconds", studyUuid, TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTime.get())); From 5014584fdc153d354059de9e9a1604a7d3cba79f Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Wed, 8 Jan 2025 11:27:05 +0100 Subject: [PATCH 14/17] fix: tests after network modification changes Signed-off-by: LE SAULNIER Kevin --- .../study/server/StudyController.java | 6 +- .../study/server/SupervisionController.java | 6 +- ...rkModificationNodeInfoRepositoryProxy.java | 1 - .../study/server/service/ConsumerService.java | 2 +- .../service/NetworkConversionService.java | 6 +- .../NetworkModificationTreeService.java | 4 +- .../service/RootNetworkNodeInfoService.java | 1 + .../study/server/service/StudyService.java | 21 +- .../server/service/SupervisionService.java | 16 +- .../gridsuite/study/server/LoadFlowTest.java | 2 +- .../study/server/NetworkModificationTest.java | 399 +++++++++++++----- .../server/NetworkModificationTreeTest.java | 44 +- .../study/server/NonEvacuatedEnergyTest.java | 2 +- .../study/server/RootNetworkTest.java | 12 +- .../study/server/SecurityAnalysisTest.java | 2 +- .../study/server/SensitivityAnalysisTest.java | 2 +- .../study/server/ShortCircuitTest.java | 2 +- .../org/gridsuite/study/server/StudyTest.java | 108 +++-- .../server/SupervisionControllerTest.java | 16 +- .../study/server/VoltageInitTest.java | 2 +- .../server/service/ReportServiceTest.java | 2 +- .../study/server/utils/StudyTestUtils.java | 2 - .../study/server/utils/WireMockUtils.java | 24 +- 23 files changed, 467 insertions(+), 215 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/StudyController.java b/src/main/java/org/gridsuite/study/server/StudyController.java index 55cb90af3..6ccb67499 100644 --- a/src/main/java/org/gridsuite/study/server/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/StudyController.java @@ -1306,7 +1306,7 @@ public ResponseEntity restoreNodes(@Parameter(description = "study uuid") @ApiResponse(responseCode = "200", description = "network modification tree"), @ApiResponse(responseCode = "404", description = "The study or the node not found")}) public ResponseEntity getNetworkModificationTree(@Parameter(description = "study uuid") @PathVariable("studyUuid") UUID studyUuid, - @Parameter(description = "root network uuid") @RequestParam("rootNetworkUuid") UUID rootNetworkUuid) { + @Parameter(description = "root network uuid") @RequestParam(value = "rootNetworkUuid", required = false) UUID rootNetworkUuid) { RootNode rootNode = networkModificationTreeService.getStudyTree(studyUuid, rootNetworkUuid); return rootNode != null ? ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(rootNode) @@ -1320,7 +1320,7 @@ public ResponseEntity getNetworkModificationTree(@Parameter(descriptio @ApiResponse(responseCode = "404", description = "The study or the parent node not found")}) public ResponseEntity getNetworkModificationSubtree(@Parameter(description = "study uuid") @PathVariable("studyUuid") UUID studyUuid, @Parameter(description = "parent node uuid") @RequestParam(value = "parentNodeUuid") UUID parentNodeUuid, - @Parameter(description = "root network uuid") @RequestParam(value = "rootNetworkUuid") UUID rootNetworkUuid) { + @Parameter(description = "root network uuid") @RequestParam(value = "rootNetworkUuid", required = false) UUID rootNetworkUuid) { NetworkModificationNode parentNode = (NetworkModificationNode) networkModificationTreeService.getStudySubtree(studyUuid, parentNodeUuid, rootNetworkUuid); return parentNode != null ? ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(parentNode) @@ -1359,7 +1359,7 @@ public ResponseEntity updateNodesColumnPositions(@RequestBody List getNode(@Parameter(description = "study uuid") @PathVariable("studyUuid") UUID studyUuid, @Parameter(description = "node uuid") @PathVariable("id") UUID nodeId, - @Parameter(description = "root network uuid") @RequestParam("rootNetworkUuid") UUID rootNetworkUuid) { + @Parameter(description = "root network uuid") @RequestParam(value = "rootNetworkUuid", required = false) UUID rootNetworkUuid) { AbstractNode node = networkModificationTreeService.getNode(nodeId, rootNetworkUuid); return node != null ? ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(node) diff --git a/src/main/java/org/gridsuite/study/server/SupervisionController.java b/src/main/java/org/gridsuite/study/server/SupervisionController.java index e58073fdc..aaaf6e2ec 100644 --- a/src/main/java/org/gridsuite/study/server/SupervisionController.java +++ b/src/main/java/org/gridsuite/study/server/SupervisionController.java @@ -95,11 +95,11 @@ public ResponseEntity getIndexedTombstonedEquipmentsCount() { return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(Long.toString(supervisionService.getIndexedTombstonedEquipmentsCount())); } - @DeleteMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/equipments/indexation") + @DeleteMapping(value = "/studies/{studyUuid}/equipments/indexation") @Operation(summary = "delete indexed equipments and tombstoned equipments for the given study") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "all indexed equipments and tombstoned equipments for the given study for the given root network have been deleted")}) - public ResponseEntity deleteStudyIndexedEquipmentsAndTombstoned(@PathVariable("studyUuid") UUID studyUuid, @PathVariable("rootNetworkUuid") UUID rootNetworkUuid) { - return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(Long.toString(supervisionService.deleteStudyIndexedEquipmentsAndTombstoned(studyUuid, rootNetworkUuid))); + public ResponseEntity deleteStudyIndexedEquipmentsAndTombstoned(@PathVariable("studyUuid") UUID studyUuid) { + return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(Long.toString(supervisionService.deleteStudyIndexedEquipmentsAndTombstoned(studyUuid))); } @GetMapping(value = "/orphan_indexed_network_uuids") diff --git a/src/main/java/org/gridsuite/study/server/networkmodificationtree/NetworkModificationNodeInfoRepositoryProxy.java b/src/main/java/org/gridsuite/study/server/networkmodificationtree/NetworkModificationNodeInfoRepositoryProxy.java index 8978e8031..edc7cbd29 100644 --- a/src/main/java/org/gridsuite/study/server/networkmodificationtree/NetworkModificationNodeInfoRepositoryProxy.java +++ b/src/main/java/org/gridsuite/study/server/networkmodificationtree/NetworkModificationNodeInfoRepositoryProxy.java @@ -9,7 +9,6 @@ import org.gridsuite.study.server.networkmodificationtree.dto.*; import org.gridsuite.study.server.networkmodificationtree.entities.NetworkModificationNodeInfoEntity; -import org.gridsuite.study.server.networkmodificationtree.entities.RootNetworkNodeInfoEntity; import org.gridsuite.study.server.repository.networkmodificationtree.NetworkModificationNodeInfoRepository; /** diff --git a/src/main/java/org/gridsuite/study/server/service/ConsumerService.java b/src/main/java/org/gridsuite/study/server/service/ConsumerService.java index 3794e921f..0bbfb7adf 100644 --- a/src/main/java/org/gridsuite/study/server/service/ConsumerService.java +++ b/src/main/java/org/gridsuite/study/server/service/ConsumerService.java @@ -395,7 +395,7 @@ public Consumer> consumeCaseImportFailed() { UUID studyUuid = receiver.getStudyUuid(); String userId = receiver.getUserId(); - switch(receiver.getCaseImportAction()) { + switch (receiver.getCaseImportAction()) { case STUDY_CREATION -> { studyService.deleteStudyIfNotCreationInProgress(studyUuid, userId); notificationService.emitStudyCreationError(studyUuid, userId, errorMessage); diff --git a/src/main/java/org/gridsuite/study/server/service/NetworkConversionService.java b/src/main/java/org/gridsuite/study/server/service/NetworkConversionService.java index 13e389e02..db4586789 100644 --- a/src/main/java/org/gridsuite/study/server/service/NetworkConversionService.java +++ b/src/main/java/org/gridsuite/study/server/service/NetworkConversionService.java @@ -30,6 +30,7 @@ import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.Map; +import java.util.Optional; import java.util.UUID; import static org.gridsuite.study.server.StudyConstants.*; @@ -71,14 +72,11 @@ public void persistNetwork(UUID caseUuid, UUID studyUuid, UUID rootNetworkUuid, UriComponentsBuilder builder = UriComponentsBuilder.fromPath(DELIMITER + NETWORK_CONVERSION_API_VERSION + "/networks") .queryParam(CASE_UUID, caseUuid) + .queryParamIfPresent(QUERY_PARAM_VARIANT_ID, Optional.ofNullable(variantId)) .queryParam(REPORT_UUID, importReportUuid) .queryParam(QUERY_PARAM_RECEIVER, receiver) .queryParam(CASE_FORMAT, caseFormat); - if (variantId != null) { - builder.queryParam(QUERY_PARAM_VARIANT_ID, variantId); - } - String path = builder .buildAndExpand() .toUriString(); diff --git a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java index 462ace3c4..8d6c6f409 100644 --- a/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java +++ b/src/main/java/org/gridsuite/study/server/service/NetworkModificationTreeService.java @@ -489,7 +489,9 @@ private AbstractNode getSimpleNode(UUID nodeId) { public AbstractNode getNode(UUID nodeId, UUID rootNetworkUuid) { AbstractNode node = getSimpleNode(nodeId); nodesRepository.findAllByParentNodeIdNode(node.getId()).stream().map(NodeEntity::getIdNode).forEach(node.getChildrenIds()::add); - completeNodeInfos(List.of(node), rootNetworkUuid); + if (rootNetworkUuid != null) { + completeNodeInfos(List.of(node), rootNetworkUuid); + } return node; } diff --git a/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java b/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java index 0ed50daa0..3f54d5203 100644 --- a/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java +++ b/src/main/java/org/gridsuite/study/server/service/RootNetworkNodeInfoService.java @@ -408,6 +408,7 @@ public List> getDeleteRootNetworkNodeInfosFutures(List new StudyException(ROOT_NETWORK_NOT_FOUND)); String variantId = rootNetworkNodeInfoEntity.getVariantId(); diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index 43c346050..40812a2a9 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -789,9 +789,9 @@ public void assertNoBuildNoComputationForRootNetworkNode(UUID nodeUuid, UUID roo } public void assertNoBuildNoComputationForNode(UUID studyUuid, UUID nodeUuid) { - rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetwork -> { - rootNetworkNodeInfoService.assertComputationNotRunning(nodeUuid, rootNetwork.getId()); - }); + rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetwork -> + rootNetworkNodeInfoService.assertComputationNotRunning(nodeUuid, rootNetwork.getId()) + ); rootNetworkNodeInfoService.assertNoRootNetworkNodeIsBuilding(studyUuid); } @@ -1482,9 +1482,9 @@ public void moveStudyNode(UUID studyUuid, UUID nodeToMoveUuid, UUID referenceNod updateStatuses(studyUuid, nodeToMoveUuid, false, true, true); oldChildren.forEach(child -> updateStatuses(studyUuid, child.getIdNode(), false, true, true)); } else { - rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> { - invalidateBuild(studyUuid, nodeToMoveUuid, rootNetworkEntity.getId(), false, true, true); - }); + rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> + invalidateBuild(studyUuid, nodeToMoveUuid, rootNetworkEntity.getId(), false, true, true) + ); } notificationService.emitElementUpdated(studyUuid, userId); } @@ -1711,9 +1711,9 @@ public void stashNode(UUID studyUuid, UUID nodeId, boolean stashChildren, String AtomicReference startTime = new AtomicReference<>(null); startTime.set(System.nanoTime()); boolean invalidateChildrenBuild = stashChildren || networkModificationTreeService.hasModifications(nodeId, false); - rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> { - invalidateBuild(studyUuid, nodeId, rootNetworkEntity.getId(), false, !invalidateChildrenBuild, true); - }); + rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> + invalidateBuild(studyUuid, nodeId, rootNetworkEntity.getId(), false, !invalidateChildrenBuild, true) + ); networkModificationTreeService.doStashNode(nodeId, stashChildren); if (startTime.get() != null) { @@ -1798,18 +1798,15 @@ public void moveModifications(UUID studyUuid, UUID targetNodeUuid, UUID originNo if (!targetNodeBelongsToSourceNodeSubTree) { // invalidate the whole subtree except maybe the target node itself (depends if we have built this node during the move) networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, targetNodeUuid, rootNetworkUuid, modificationResult)); - //TODO : should take rootnetworkuuid as param updateStatuses(studyUuid, targetNodeUuid, buildTargetNode, true, true); } if (moveBetweenNodes) { // invalidate the whole subtree including the source node networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, originNodeUuid, rootNetworkUuid, modificationResult)); - //TODO : should take rootnetworkuuid as param updateStatuses(studyUuid, originNodeUuid, false, true, true); } }); } finally { - //TODO : should take rootnetworkuuid as param notificationService.emitEndModificationEquipmentNotification(studyUuid, targetNodeUuid, childrenUuids); if (moveBetweenNodes) { notificationService.emitEndModificationEquipmentNotification(studyUuid, originNodeUuid, originNodeChildrenUuids); diff --git a/src/main/java/org/gridsuite/study/server/service/SupervisionService.java b/src/main/java/org/gridsuite/study/server/service/SupervisionService.java index 2d0d260d3..418a6a78c 100644 --- a/src/main/java/org/gridsuite/study/server/service/SupervisionService.java +++ b/src/main/java/org/gridsuite/study/server/service/SupervisionService.java @@ -8,7 +8,6 @@ import org.gridsuite.study.server.StudyException; import org.gridsuite.study.server.elasticsearch.EquipmentInfosService; -import org.gridsuite.study.server.networkmodificationtree.dto.RootNode; import org.gridsuite.study.server.networkmodificationtree.entities.RootNetworkNodeInfoEntity; import org.gridsuite.study.server.repository.rootnetwork.RootNetworkNodeInfoRepository; import org.gridsuite.study.server.service.dynamicsimulation.DynamicSimulationService; @@ -135,17 +134,22 @@ public long getIndexedTombstonedEquipmentsCount() { } @Transactional - public Long deleteStudyIndexedEquipmentsAndTombstoned(UUID studyUuid, UUID rootNetworkUuid) { + public Long deleteStudyIndexedEquipmentsAndTombstoned(UUID studyUuid) { AtomicReference startTime = new AtomicReference<>(); startTime.set(System.nanoTime()); - UUID networkUUID = rootNetworkService.getNetworkUuid(rootNetworkUuid); - Long nbIndexesToDelete = getStudyIndexedEquipmentsCount(networkUUID) + getStudyIndexedTombstonedEquipmentsCount(networkUUID); - equipmentInfosService.deleteAllByNetworkUuid(networkUUID); + AtomicReference nbIndexesToDelete = new AtomicReference<>(0L); + + rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> { + UUID networkUUID = rootNetworkService.getNetworkUuid(rootNetworkEntity.getId()); + nbIndexesToDelete.updateAndGet(v -> v + getStudyIndexedEquipmentsCount(networkUUID) + getStudyIndexedTombstonedEquipmentsCount(networkUUID)); + equipmentInfosService.deleteAllByNetworkUuid(networkUUID); + }); + studyService.updateStudyIndexationStatus(studyUuid, StudyIndexationStatus.NOT_INDEXED); LOGGER.trace("Indexed equipments deletion for study \"{}\": {} seconds", studyUuid, TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTime.get())); - return nbIndexesToDelete; + return nbIndexesToDelete.get(); } private Integer deleteLoadflowResults() { diff --git a/src/test/java/org/gridsuite/study/server/LoadFlowTest.java b/src/test/java/org/gridsuite/study/server/LoadFlowTest.java index c9b60d54b..13c703e8e 100644 --- a/src/test/java/org/gridsuite/study/server/LoadFlowTest.java +++ b/src/test/java/org/gridsuite/study/server/LoadFlowTest.java @@ -519,7 +519,7 @@ void testDeleteLoadFlowResults(final MockWebServer server) throws Exception { void testResetUuidResultWhenLFFailed() throws Exception { UUID resultUuid = UUID.randomUUID(); StudyEntity studyEntity = insertDummyStudy(UUID.randomUUID(), UUID.randomUUID(), LOADFLOW_PARAMETERS_UUID); - RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId()); + RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId(), null); NetworkModificationNode modificationNode = createNetworkModificationNode(studyEntity.getId(), rootNode.getId(), UUID.randomUUID(), VARIANT_ID, "node 1"); UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); String resultUuidJson = objectMapper.writeValueAsString(new NodeReceiver(modificationNode.getId(), rootNetworkUuid)); diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java index 21696541a..28ea53f53 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java @@ -227,6 +227,7 @@ class NetworkModificationTest { private UUID userNoProfileStubId; private static final String ERROR_MESSAGE = "nullPointerException: unexpected null somewhere"; + private ObjectMapper objectMapper; @BeforeEach void setup(final MockWebServer server) { @@ -553,6 +554,7 @@ void testLocalBuildValue() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); String userId = "userId"; NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, @@ -561,7 +563,7 @@ void testLocalBuildValue() throws Exception { Map createLoadInfos = Map.of("type", ModificationType.LOAD_CREATION, "equipmentId", "loadId"); String jsonCreateLoadInfos = mapper.writeValueAsString(createLoadInfos); - wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(Optional.empty())); // Mark the node status as built RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); @@ -575,12 +577,14 @@ void testLocalBuildValue() throws Exception { // Create network modification on BUILT modification node Optional networkModificationResult = createModificationResultWithElementImpact(SimpleImpactType.CREATION, IdentifiableType.LOAD, "loadId", Set.of("s1")); - wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); + wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(networkModificationResult)); NetworkImpactsInfos expectedPayload = NetworkImpactsInfos.builder().impactedSubstationsIds(ImmutableSet.of("s1")).deletedEquipments(ImmutableSet.of()).build(); // Build first node with errors networkModificationResult.get().setApplicationStatus(NetworkModificationResult.ApplicationStatus.WITH_ERRORS); - UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(List.of(networkModificationResult))); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -594,11 +598,14 @@ void testLocalBuildValue() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, rootNetworkUuid).getGlobalBuildStatus()); - wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, jsonCreateLoadInfos); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // Build second node is OK networkModificationResult.get().setApplicationStatus(NetworkModificationResult.ApplicationStatus.ALL_OK); - stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); + stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(List.of(networkModificationResult))); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -612,7 +619,9 @@ void testLocalBuildValue() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, rootNetworkUuid).getGlobalBuildStatus()); - wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, jsonCreateLoadInfos); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode2Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); //Build modification node 2, local status should be BUILT and computed one should be BUILT_WITH_ERRORS assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, rootNetworkUuid).getLocalBuildStatus()); @@ -627,8 +636,8 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); - UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -653,7 +662,9 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception .andExpect(status().isForbidden()); // update switch on first modification node - UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -663,7 +674,9 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, bodyJson, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, bodyJson); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode1Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); mvcResult = mockMvc.perform(get("/v1/studies").header(USER_ID_HEADER, userId)).andExpectAll( status().isOk(), @@ -685,7 +698,9 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, bodyJson, NETWORK_UUID_STRING, VARIANT_ID_2); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, bodyJson); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode2Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // test build status on switch modification RootNetworkNodeInfoEntity rootNetworkNodeInfo1Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode1.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); @@ -697,7 +712,8 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception Optional networkModificationResult = createModificationResultWithElementImpact(SimpleImpactType.MODIFICATION, IdentifiableType.SWITCH, "switchId", Set.of("s1", "s2", "s3")); - stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); + stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(List.of(networkModificationResult))); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -709,16 +725,18 @@ void testNetworkModificationSwitch(final MockWebServer server) throws Exception checkSwitchModificationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid, modificationNode2Uuid), expectedPayload); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, bodyJson, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, bodyJson); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode1Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); Set requests = TestUtils.getRequestsWithBodyDone(1, server); assertTrue(requests.stream().anyMatch(r -> r.getPath().matches("/v1/reports"))); // modificationNode2 is still built - assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode1Uuid, rootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode1Uuid, firstRootNetworkUuid).getGlobalBuildStatus()); // modificationNode2 is now invalid - assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, rootNetworkUuid).getGlobalBuildStatus()); + assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode2Uuid, firstRootNetworkUuid).getGlobalBuildStatus()); } @Test @@ -729,6 +747,7 @@ void testNetworkModificationEquipment() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node 1", userId); UUID modificationNodeUuid = modificationNode.getId(); @@ -749,7 +768,9 @@ void testNetworkModificationEquipment() throws Exception { .andExpect(status().isForbidden()); //update equipment - UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -758,7 +779,9 @@ void testNetworkModificationEquipment() throws Exception { checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - wireMockUtils.verifyNetworkModificationPost(stubId, bodyJson, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, bodyJson); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); mvcResult = mockMvc.perform(get("/v1/studies").header(USER_ID_HEADER, "userId").header(USER_ID_HEADER, "userId")).andExpectAll( status().isOk(), @@ -780,7 +803,9 @@ void testNetworkModificationEquipment() throws Exception { checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid2); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, bodyJson, NETWORK_UUID_STRING, VARIANT_ID_2); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, bodyJson); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid2, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); } @Test @@ -788,6 +813,7 @@ void testCreateGenerator() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -819,7 +845,9 @@ void testCreateGenerator() throws Exception { .andExpect(status().isForbidden()); // create generator on first modification node - UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -829,7 +857,9 @@ void testCreateGenerator() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, bodyJsonCreate, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, bodyJsonCreate); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode1Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // create generator on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) @@ -841,7 +871,9 @@ void testCreateGenerator() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, bodyJsonCreate, NETWORK_UUID_STRING, VARIANT_ID_2); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, bodyJsonCreate); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode2Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // update generator creation body.replace("generatorId", "generatorId2"); @@ -880,6 +912,7 @@ void testCreateShuntsCompensator() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -894,7 +927,9 @@ void testCreateShuntsCompensator() throws Exception { .andExpect(status().isForbidden()); // create shuntCompensator on modification node child of root node - UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createShuntCompensatorAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -904,7 +939,9 @@ void testCreateShuntsCompensator() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createShuntCompensatorAttributes, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createShuntCompensatorAttributes); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode1Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // update shunt compensator creation UUID stubPutId = wireMockUtils.stubNetworkModificationPut(MODIFICATION_UUID); @@ -934,6 +971,7 @@ void testCreateLine() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -957,7 +995,9 @@ void testCreateLine() throws Exception { .andExpect(status().isForbidden()); // create line on first modification node - UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createLineAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -967,7 +1007,9 @@ void testCreateLine() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createLineAttributes, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createLineAttributes); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode1Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // create line on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) @@ -979,7 +1021,9 @@ void testCreateLine() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createLineAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createLineAttributes); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode2Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // update line creation String lineAttributesUpdated = "{\"type\":\"" + ModificationType.LINE_CREATION @@ -1023,6 +1067,7 @@ void testCreateTwoWindingsTransformer() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -1040,7 +1085,9 @@ void testCreateTwoWindingsTransformer() throws Exception { .andExpect(status().isForbidden()); // create 2WT on first modification node - UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1050,7 +1097,9 @@ void testCreateTwoWindingsTransformer() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createTwoWindingsTransformerAttributes); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode1Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // create 2WT on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) @@ -1062,7 +1111,9 @@ void testCreateTwoWindingsTransformer() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createTwoWindingsTransformerAttributes); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode2Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // update Two Windings Transformer creation String twoWindingsTransformerAttributesUpdated = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; @@ -1143,6 +1194,7 @@ void testUpdateLines() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -1158,7 +1210,9 @@ void testUpdateLines() throws Exception { String bodyJsonCreate1 = mapper.writeValueAsString(bodyLineInfos); // change line status on root node (not allowed) - UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(bodyJsonCreate1).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1174,7 +1228,9 @@ void testUpdateLines() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPost(stubPostId, bodyJsonCreate1, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, bodyJsonCreate1); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode1Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); bodyLineInfos.put("equipmentId", "lineFailedId"); String bodyJsonCreate2 = mapper.writeValueAsString(bodyLineInfos); @@ -1185,13 +1241,14 @@ void testUpdateLines() throws Exception { .andExpect(status().isBadRequest()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - wireMockUtils.verifyNetworkModificationPost(stubPostId, bodyJsonCreate2, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPost(stubPostId, bodyJsonCreate2); // trip line bodyLineInfos.put("equipmentId", "line23"); bodyLineInfos.put("action", "trip"); String bodyJsonCreate3 = mapper.writeValueAsString(bodyLineInfos); - stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate3).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1201,7 +1258,9 @@ void testUpdateLines() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPost(stubPostId, bodyJsonCreate3, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, bodyJsonCreate3); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode1Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); bodyLineInfos.put("equipmentId", "lineFailedId"); String bodyJsonCreate4 = mapper.writeValueAsString(bodyLineInfos); @@ -1212,13 +1271,14 @@ void testUpdateLines() throws Exception { .andExpect(status().isBadRequest()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - wireMockUtils.verifyNetworkModificationPost(stubPostId, bodyJsonCreate4, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPost(stubPostId, bodyJsonCreate4); // energise line end bodyLineInfos.put("equipmentId", "line13"); bodyLineInfos.put("action", "energiseEndOne"); String bodyJsonCreate5 = mapper.writeValueAsString(bodyLineInfos); - stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate5).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1228,7 +1288,9 @@ void testUpdateLines() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPost(stubPostId, bodyJsonCreate5, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, bodyJsonCreate5); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode1Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); bodyLineInfos.put("equipmentId", "lineFailedId"); String bodyJsonCreate6 = mapper.writeValueAsString(bodyLineInfos); @@ -1239,13 +1301,14 @@ void testUpdateLines() throws Exception { .andExpect(status().isBadRequest()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - wireMockUtils.verifyNetworkModificationPost(stubPostId, bodyJsonCreate6, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPost(stubPostId, bodyJsonCreate6); // switch on line bodyLineInfos.put("equipmentId", "line13"); bodyLineInfos.put("action", "switchOn"); String bodyJsonCreate7 = mapper.writeValueAsString(bodyLineInfos); - stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate7).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1255,7 +1318,9 @@ void testUpdateLines() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPost(stubPostId, bodyJsonCreate7, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, bodyJsonCreate7); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode1Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); bodyLineInfos.put("equipmentId", "lineFailedId"); String bodyJsonCreate8 = mapper.writeValueAsString(bodyLineInfos); @@ -1266,11 +1331,12 @@ void testUpdateLines() throws Exception { .andExpect(status().isBadRequest()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - wireMockUtils.verifyNetworkModificationPost(stubPostId, bodyJsonCreate8, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPost(stubPostId, bodyJsonCreate8); // switch on line on second modification node String bodyJsonCreate9 = bodyJsonCreate7; - stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(bodyJsonCreate9).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1280,7 +1346,10 @@ void testUpdateLines() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, bodyJsonCreate9, NETWORK_UUID_STRING, VARIANT_ID_2); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, bodyJsonCreate9); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode2Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); + } @Test @@ -1288,6 +1357,7 @@ void testCreateLoad() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -1308,7 +1378,9 @@ void testCreateLoad() throws Exception { .andExpect(status().isForbidden()); // create load on first modification node - UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createLoadAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1318,7 +1390,9 @@ void testCreateLoad() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createLoadAttributes); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode1Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // create load on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) @@ -1330,7 +1404,9 @@ void testCreateLoad() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createLoadAttributes); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode2Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // update load creation String loadAttributesUpdated = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId2\",\"loadName\":\"loadName2\",\"loadType\":\"UNDEFINED\",\"activePower\":\"50.0\",\"reactivePower\":\"25.0\",\"voltageLevelId\":\"idVL2\",\"busId\":\"idBus2\"}"; @@ -1363,6 +1439,7 @@ void testModifyLoad() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -1380,7 +1457,9 @@ void testModifyLoad() throws Exception { .andExpect(status().isForbidden()); // modify load on first modification node - UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(loadModificationAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1390,7 +1469,9 @@ void testModifyLoad() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, loadModificationAttributes, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, loadModificationAttributes); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // modify load on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid2) @@ -1402,7 +1483,9 @@ void testModifyLoad() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid2); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid2); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, loadModificationAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, loadModificationAttributes); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid2, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // update load modification UUID stubPutId = wireMockUtils.stubNetworkModificationPut(MODIFICATION_UUID); @@ -1423,6 +1506,7 @@ void testModifyEquipment() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); UUID modificationNodeUuid = modificationNode.getId(); @@ -1437,7 +1521,9 @@ void testModifyEquipment() throws Exception { .andExpect(status().isForbidden()); // modify generator on first modification node - UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(equipmentModificationAttribute).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1447,7 +1533,9 @@ void testModifyEquipment() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, equipmentModificationAttribute, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, equipmentModificationAttribute); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // modify generator on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid2) @@ -1459,7 +1547,9 @@ void testModifyEquipment() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid2); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid2); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, equipmentModificationAttribute, NETWORK_UUID_STRING, VARIANT_ID_2); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, equipmentModificationAttribute); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid2, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // update generator modification String generatorAttributesUpdated = "{\"type\":\"" + ModificationType.GENERATOR_MODIFICATION + "\",\"generatorId\":\"generatorId1\",\"generatorType\":\"FICTITIOUS\",\"activePower\":\"70.0\"}"; @@ -1480,6 +1570,7 @@ void testCreateSubstation() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -1497,7 +1588,9 @@ void testCreateSubstation() throws Exception { .andExpect(status().isForbidden()); // create substation on first modification node - UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createSubstationAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1507,7 +1600,9 @@ void testCreateSubstation() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createSubstationAttributes, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createSubstationAttributes); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode1Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // create substation on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) @@ -1519,7 +1614,9 @@ void testCreateSubstation() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createSubstationAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createSubstationAttributes); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode2Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // update substation creation UUID stubPutId = wireMockUtils.stubNetworkModificationPut(MODIFICATION_UUID); @@ -1551,6 +1648,7 @@ void testCreateVoltageLevel() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node 1", userId); UUID modificationNode1Uuid = modificationNode1.getId(); @@ -1568,7 +1666,9 @@ void testCreateVoltageLevel() throws Exception { .andExpect(status().isForbidden()); // create voltage level - UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createVoltageLevelAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1578,7 +1678,9 @@ void testCreateVoltageLevel() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createVoltageLevelAttributes, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createVoltageLevelAttributes); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode1Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // create voltage level on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) @@ -1590,7 +1692,9 @@ void testCreateVoltageLevel() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createVoltageLevelAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createVoltageLevelAttributes); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode2Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // update voltage level creation UUID stubPutId = wireMockUtils.stubNetworkModificationPut(MODIFICATION_UUID); @@ -1624,6 +1728,7 @@ void testLineSplitWithVoltageLevel() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); @@ -1641,7 +1746,9 @@ void testLineSplitWithVoltageLevel() throws Exception { lineSplitWoVL.setType(ModificationType.LINE_SPLIT_WITH_VOLTAGE_LEVEL); String lineSplitWoVLasJSON = mapper.writeValueAsString(lineSplitWoVL); - UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(lineSplitWoVLasJSON).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1651,7 +1758,9 @@ void testLineSplitWithVoltageLevel() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPost(stubPostId, lineSplitWoVLasJSON, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, lineSplitWoVLasJSON); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); UUID stubPutId = wireMockUtils.stubNetworkModificationPutWithBody(MODIFICATION_UUID, lineSplitWoVLasJSON); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) @@ -1683,7 +1792,7 @@ void testLineSplitWithVoltageLevel() throws Exception { content().string("400 BAD_REQUEST")); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - wireMockUtils.verifyNetworkModificationPost(stubPostId, badBody, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPost(stubPostId, badBody); wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, badBody); } @@ -1692,6 +1801,7 @@ void testLineAttachToVoltageLevel() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); @@ -1702,7 +1812,9 @@ void testLineAttachToVoltageLevel() throws Exception { String createLineAttachToVoltageLevelAttributes = "{\"type\":\"" + ModificationType.LINE_ATTACH_TO_VOLTAGE_LEVEL + "\",\"lineToAttachToId\":\"line3\",\"percent\":\"10\",\"mayNewVoltageLevelInfos\":" + createVoltageLevelAttributes + ",\"attachmentLine\":" + createLineAttributes + "}"; - UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(createLineAttachToVoltageLevelAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1712,7 +1824,9 @@ void testLineAttachToVoltageLevel() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPost(stubPostId, createLineAttachToVoltageLevelAttributes, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createLineAttachToVoltageLevelAttributes); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); UUID stubPutId = wireMockUtils.stubNetworkModificationPutWithBody(MODIFICATION_UUID, createLineAttachToVoltageLevelAttributes); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) @@ -1731,12 +1845,15 @@ void testLinesAttachToSplitLines() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); String createLinesAttachToSplitLinesAttributes = "{\"type\":\"" + ModificationType.LINES_ATTACH_TO_SPLIT_LINES + "\",\"lineToAttachTo1Id\":\"line1\",\"lineToAttachTo2Id\":\"line2\",\"attachedLineId\":\"line3\",\"voltageLevelId\":\"vl1\",\"bbsBusId\":\"v1bbs\",\"replacingLine1Id\":\"replacingLine1Id\",\"replacingLine1Name\":\"replacingLine1Name\",\"replacingLine2Id\":\"replacingLine2Id\",\"replacingLine2Name\":\"replacingLine2Name\"}"; - UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(createLinesAttachToSplitLinesAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1746,7 +1863,9 @@ void testLinesAttachToSplitLines() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPost(stubPostId, createLinesAttachToSplitLinesAttributes, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createLinesAttachToSplitLinesAttributes); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); UUID stubPutId = wireMockUtils.stubNetworkModificationPutWithBody(MODIFICATION_UUID, createLinesAttachToSplitLinesAttributes); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) @@ -1774,7 +1893,7 @@ void testLinesAttachToSplitLines() throws Exception { .andExpect(status().isBadRequest()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - wireMockUtils.verifyNetworkModificationPost(stubPostId, badBody, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPost(stubPostId, badBody); wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, badBody); } @@ -1787,11 +1906,14 @@ void testScaling(ModificationType scalingType) throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); - UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(requestBody).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1801,7 +1923,9 @@ void testScaling(ModificationType scalingType) throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPost(stubPostId, requestBody, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, requestBody); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); UUID stubPutId = wireMockUtils.stubNetworkModificationPutWithBody(MODIFICATION_UUID, requestBody); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) @@ -1822,7 +1946,7 @@ void testScaling(ModificationType scalingType) throws Exception { .andExpect(status().is4xxClientError()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - wireMockUtils.verifyNetworkModificationPost(stubPostId, requestBody, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPost(stubPostId, requestBody); stubPutId = wireMockUtils.stubNetworkModificationPutWithBodyAndError(MODIFICATION_UUID, requestBody); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) @@ -1839,13 +1963,16 @@ void testDeleteVoltageLevelOnline() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); String createDeleteVoltageLevelOnlineAttributes = "{\"type\":\"" + ModificationType.DELETE_VOLTAGE_LEVEL_ON_LINE + "\",\"lineToAttachTo1Id\":\"line1\",\"lineToAttachTo2Id\":\"line2\",\"replacingLine1Id\":\"replacingLine1Id\",\"replacingLine1Name\":\"replacingLine1Name\"}"; - UUID stubIdPost = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(createDeleteVoltageLevelOnlineAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1854,7 +1981,9 @@ void testDeleteVoltageLevelOnline() throws Exception { checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - wireMockUtils.verifyNetworkModificationPost(stubIdPost, createDeleteVoltageLevelOnlineAttributes, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createDeleteVoltageLevelOnlineAttributes); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); UUID stubIdPut = wireMockUtils.stubNetworkModificationPutWithBody(MODIFICATION_UUID, createDeleteVoltageLevelOnlineAttributes); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) @@ -1874,7 +2003,7 @@ void testDeleteVoltageLevelOnline() throws Exception { .andExpect(status().isBadRequest()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - wireMockUtils.verifyNetworkModificationPost(stubIdPostErr, badBody, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPost(stubIdPostErr, badBody); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) .header(USER_ID_HEADER, userId) @@ -1890,12 +2019,15 @@ void testDeleteAttachingline() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); UUID modificationNodeUuid = modificationNode.getId(); String createDeleteAttachingLineAttributes = "{\"type\":\"" + ModificationType.DELETE_ATTACHING_LINE + "\",\"lineToAttachTo1Id\":\"line1\",\"lineToAttachTo2Id\":\"line2\",\"attachedLineId\":\"line3\",\"replacingLine1Id\":\"replacingLine1Id\",\"replacingLine1Name\":\"replacingLine1Name\"}"; - UUID stubIdPost = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(createDeleteAttachingLineAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1904,7 +2036,9 @@ void testDeleteAttachingline() throws Exception { checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - wireMockUtils.verifyNetworkModificationPost(stubIdPost, createDeleteAttachingLineAttributes, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createDeleteAttachingLineAttributes); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); UUID stubIdPut = wireMockUtils.stubNetworkModificationPutWithBody(MODIFICATION_UUID, createDeleteAttachingLineAttributes); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) @@ -1925,7 +2059,7 @@ void testDeleteAttachingline() throws Exception { .andExpect(status().isBadRequest()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - wireMockUtils.verifyNetworkModificationPost(stubIdPostErr, badBody, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPost(stubIdPostErr, badBody); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) .content(badBody).contentType(MediaType.APPLICATION_JSON) @@ -2033,20 +2167,26 @@ void testDuplicateModification() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); UUID rootNodeUuid = getRootNode(studyUuid).getId(); NetworkModificationNode node1 = createNetworkModificationNode(studyUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "New node 1", "userId"); UUID nodeUuid1 = node1.getId(); UUID modification1 = UUID.randomUUID(); UUID modification2 = UUID.randomUUID(); + UUID duplicatedModification1 = UUID.randomUUID(); + UUID duplicatedModification2 = UUID.randomUUID(); String modificationUuidListBody = mapper.writeValueAsString(Arrays.asList(modification1, modification2)); + String duplicatedModificationUuidListBody = mapper.writeValueAsString(Arrays.asList(duplicatedModification1, duplicatedModification2)); UUID groupStubId = wireMockServer.stubFor(WireMock.any(WireMock.urlPathMatching("/v1/groups/.*")) .withQueryParam("action", WireMock.equalTo("COPY")) .willReturn(WireMock.ok() - .withBody(mapper.writeValueAsString(Optional.empty())) + .withBody(duplicatedModificationUuidListBody) .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); + // duplicate 2 modifications in node1 mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY", studyUuid, nodeUuid1) @@ -2064,12 +2204,10 @@ void testDuplicateModification() throws Exception { String expectedBody = mapper.writeValueAsString(expectedList); String url = "/v1/groups/" + node1.getModificationGroupUuid(); wireMockUtils.verifyPutRequestWithUrlMatching(groupStubId, url, Map.of( - "action", WireMock.equalTo("COPY"), - "networkUuid", WireMock.equalTo(NETWORK_UUID_STRING), - "reportUuid", WireMock.matching(".*"), - "reporterId", WireMock.equalTo(node1.getId().toString()), - "variantId", WireMock.equalTo(VARIANT_ID)), + "action", WireMock.equalTo("COPY")), expectedBody); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(duplicatedModification1, duplicatedModification2), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, node1.getId(), NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // now we do the same but on a built node RootNetworkNodeInfoEntity rootNetworkNodeInfo1Entity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(nodeUuid1, studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); @@ -2079,9 +2217,11 @@ void testDuplicateModification() throws Exception { groupStubId = wireMockServer.stubFor(WireMock.any(WireMock.urlPathMatching("/v1/groups/.*")) .withQueryParam("action", WireMock.equalTo("COPY")) .willReturn(WireMock.ok() - .withBody(mapper.writeValueAsString(Optional.of(NetworkModificationResult.builder().build()))) + .withBody(duplicatedModificationUuidListBody) .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))).getId(); + stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(List.of(Optional.of(NetworkModificationResult.builder().build())))); + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}?action=COPY", studyUuid, nodeUuid1) .contentType(MediaType.APPLICATION_JSON) @@ -2101,12 +2241,9 @@ void testDuplicateModification() throws Exception { expectedBody = mapper.writeValueAsString(expectedList); url = "/v1/groups/" + node1.getModificationGroupUuid(); wireMockUtils.verifyPutRequestWithUrlMatching(groupStubId, url, Map.of( - "action", WireMock.equalTo("COPY"), - "networkUuid", WireMock.equalTo(NETWORK_UUID_STRING), - "reportUuid", WireMock.matching(".*"), - "reporterId", WireMock.equalTo(node1.getId().toString()), - "variantId", WireMock.equalTo(VARIANT_ID)), + "action", WireMock.equalTo("COPY")), expectedBody); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); } @Test @@ -2258,6 +2395,7 @@ void testDeleteEquipment() throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); @@ -2280,7 +2418,9 @@ void testDeleteEquipment() throws Exception { .andExpect(status().isForbidden()); // delete equipment on first modification node - UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -2290,7 +2430,9 @@ void testDeleteEquipment() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, bodyJson, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, bodyJson); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode1Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // delete equipment on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) @@ -2302,7 +2444,9 @@ void testDeleteEquipment() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, bodyJson, NETWORK_UUID_STRING, VARIANT_ID_2); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, bodyJson); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode2Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // update equipment deletion UUID stubPutId = wireMockUtils.stubNetworkModificationPut(MODIFICATION_UUID); @@ -2321,7 +2465,7 @@ void testDeleteEquipment() throws Exception { void testNodesInvalidation(final MockWebServer server) throws Exception { String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); - UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyEntity.getId()); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", BuildStatus.BUILT, userId); @@ -2380,7 +2524,9 @@ void testNodesInvalidation(final MockWebServer server) throws Exception { // Create a network modification on node 2 (not built) -> build invalidation of node 3 Map createLoadInfos = Map.of("type", ModificationType.LOAD_CREATION, "equipmentId", "loadId"); String jsonCreateLoadInfos = mapper.writeValueAsString(createLoadInfos); - stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -2390,8 +2536,10 @@ void testNodesInvalidation(final MockWebServer server) throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode3Uuid, rootNetworkUuid).getGlobalBuildStatus()); - wireMockUtils.verifyNetworkModificationPost(stubUuid, jsonCreateLoadInfos, NETWORK_UUID_STRING); + assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode3Uuid, firstRootNetworkUuid).getGlobalBuildStatus()); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, jsonCreateLoadInfos); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode2Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); requests = TestUtils.getRequestsWithBodyDone(1, server); assertEquals(1, requests.stream().filter(r -> r.getPath().matches("/v1/reports")).count()); @@ -2402,6 +2550,7 @@ void testRemoveLoadFlowComputationReport(final MockWebServer server) throws Exce String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", BuildStatus.BUILT, userId); UUID modificationNode1Uuid = modificationNode1.getId(); @@ -2438,7 +2587,9 @@ void testRemoveLoadFlowComputationReport(final MockWebServer server) throws Exce String bodyJson = mapper.writeValueAsString(body); // add this modification to the node => invalidate the LF - UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -2448,7 +2599,9 @@ void testRemoveLoadFlowComputationReport(final MockWebServer server) throws Exce checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, bodyJson, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, bodyJson); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNode1Uuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); var requests = TestUtils.getRequestsDone(17, server); // 3 x 8 computations List.of(LOADFLOW_RESULT_UUID, SECURITY_ANALYSIS_RESULT_UUID, SENSITIVITY_ANALYSIS_RESULT_UUID, SENSITIVITY_ANALYSIS_NON_EVACUATED_ENERGY_RESULT_UUID, @@ -2463,7 +2616,7 @@ void testRemoveLoadFlowComputationReport(final MockWebServer server) throws Exce @Test void testUpdateOfBuildStatus() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); - UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyEntity.getId()); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); String userId = "userId"; @@ -2475,7 +2628,9 @@ void testUpdateOfBuildStatus() throws Exception { String jsonCreateLoadInfos = mapper.writeValueAsString(createLoadInfos); // Create network modification on NOT_BUILT modification node - UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -2485,8 +2640,10 @@ void testUpdateOfBuildStatus() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, rootNetworkUuid).getGlobalBuildStatus()); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING, VARIANT_ID); + assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, firstRootNetworkUuid).getGlobalBuildStatus()); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, jsonCreateLoadInfos); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // Mark the node status as built RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(modificationNode.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid)).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); @@ -2496,7 +2653,8 @@ void testUpdateOfBuildStatus() throws Exception { // Create network modification on BUILT modification node Optional networkModificationResult = createModificationResultWithElementImpact(SimpleImpactType.CREATION, IdentifiableType.LOAD, "loadId", Set.of("s1")); - stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); + stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(List.of(networkModificationResult))); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -2508,12 +2666,15 @@ void testUpdateOfBuildStatus() throws Exception { checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, rootNetworkUuid).getGlobalBuildStatus()); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING, VARIANT_ID); + assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, firstRootNetworkUuid).getGlobalBuildStatus()); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, jsonCreateLoadInfos); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // Built with warnings networkModificationResult.get().setApplicationStatus(NetworkModificationResult.ApplicationStatus.WITH_WARNINGS); - stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); + stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(List.of(networkModificationResult))); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -2525,12 +2686,15 @@ void testUpdateOfBuildStatus() throws Exception { checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - assertEquals(BuildStatus.BUILT_WITH_WARNING, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, rootNetworkUuid).getGlobalBuildStatus()); - wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING); + assertEquals(BuildStatus.BUILT_WITH_WARNING, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, firstRootNetworkUuid).getGlobalBuildStatus()); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, jsonCreateLoadInfos); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // Built with errors networkModificationResult.get().setApplicationStatus(NetworkModificationResult.ApplicationStatus.WITH_ERRORS); - stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); + stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(List.of(networkModificationResult))); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -2542,8 +2706,10 @@ void testUpdateOfBuildStatus() throws Exception { checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, rootNetworkUuid).getGlobalBuildStatus()); - wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING); + assertEquals(BuildStatus.BUILT_WITH_ERROR, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid, firstRootNetworkUuid).getGlobalBuildStatus()); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, jsonCreateLoadInfos); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); } private void testBuildWithNodeUuid(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String userId, UUID profileStubId) throws Exception { @@ -2868,6 +3034,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU void testCreateModificationWithErrors() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); String userId = "userId"; NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, @@ -2878,7 +3045,9 @@ void testCreateModificationWithErrors() throws Exception { String jsonCreateLoadInfos = mapper.writeValueAsString(createLoadInfos); // Create network modification on first modification node - UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -2888,18 +3057,20 @@ void testCreateModificationWithErrors() throws Exception { checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, jsonCreateLoadInfos); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, modificationNodeUuid, NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // String message error String contentErrorMessage = "Internal Server Error"; - stubId = wireMockUtils.stubNetworkModificationPostWithError(jsonCreateLoadInfos); + UUID stubId = wireMockUtils.stubNetworkModificationPostWithError(jsonCreateLoadInfos); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) .andExpectAll(status().isBadRequest(), content().string(contentErrorMessage)); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos); // Json message error stubId = wireMockUtils.stubNetworkModificationPostWithError(jsonCreateLoadInfos, String.format("{\"message\" : \"%s\"}", contentErrorMessage)); @@ -2909,7 +3080,7 @@ void testCreateModificationWithErrors() throws Exception { .andExpectAll(status().isBadRequest(), content().string(contentErrorMessage)); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos); // Bad json message error contentErrorMessage = String.format("{\"foo\" : \"%s\"}", contentErrorMessage); @@ -2920,7 +3091,7 @@ void testCreateModificationWithErrors() throws Exception { .andExpectAll(status().isBadRequest(), content().string(contentErrorMessage)); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPost(stubId, jsonCreateLoadInfos); } private void checkElementUpdatedMessageSent(UUID elementUuid, String userId) { diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java index 6497736cf..06bfbeb20 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java @@ -345,8 +345,13 @@ void testGetRoot() throws Exception { } private AbstractNode getNode(UUID studyUuid, UUID idNode) throws Exception { + return getNode(studyUuid, idNode, null); + } + + private AbstractNode getNode(UUID studyUuid, UUID idNode, UUID rootNetworkUuid) throws Exception { - return objectMapper.readValue(mockMvc.perform(get("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, idNode)) + return objectMapper.readValue(mockMvc.perform(get("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, idNode) + .param("rootNetworkUuid", rootNetworkUuid != null ? rootNetworkUuid.toString() : null)) .andExpect(status().isOk()) .andReturn() .getResponse() @@ -355,7 +360,12 @@ private AbstractNode getNode(UUID studyUuid, UUID idNode) throws Exception { } private RootNode getRootNode(UUID study) throws Exception { - return objectMapper.readValue(mockMvc.perform(get("/v1/studies/{uuid}/tree", study)) + return getRootNode(study, null); + } + + private RootNode getRootNode(UUID study, UUID rootNetworkUuid) throws Exception { + return objectMapper.readValue(mockMvc.perform(get("/v1/studies/{uuid}/tree", study) + .param("rootNetworkUuid", rootNetworkUuid != null ? rootNetworkUuid.toString() : null)) .andExpect(status().isOk()) .andReturn() .getResponse() @@ -366,10 +376,11 @@ private RootNode getRootNode(UUID study) throws Exception { void testNodeCreation() throws Exception { String userId = "userId"; RootNode root = createRoot(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(root.getStudyId()); // Check build status initialized to NOT_BUILT if null final NetworkModificationNode node1 = buildNetworkModificationNode("not_built", "not built node", MODIFICATION_GROUP_UUID_2, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); createNode(root.getStudyId(), root, node1, userId); - root = getRootNode(root.getStudyId()); + root = getRootNode(root.getStudyId(), firstRootNetworkUuid); List children = root.getChildren(); assertEquals(1, children.size()); NetworkModificationNode networkModificationNode = (NetworkModificationNode) children.get(0); @@ -380,7 +391,7 @@ void testNodeCreation() throws Exception { // Check built status correctly initialized final NetworkModificationNode node2 = buildNetworkModificationNode("built", "built node", MODIFICATION_GROUP_UUID, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT); createNode(root.getStudyId(), root, node2, userId); - root = getRootNode(root.getStudyId()); + root = getRootNode(root.getStudyId(), firstRootNetworkUuid); children = root.getChildren(); assertEquals(1, children.size()); networkModificationNode = (NetworkModificationNode) children.get(0); @@ -395,11 +406,12 @@ void testNodeStashAndRestore() throws Exception { String userId = "userId"; RootNode root = createRoot(); UUID studyId = root.getStudyId(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyId); // Check build status initialized to NOT_BUILT if null final NetworkModificationNode node1 = buildNetworkModificationNode("not_built", "not built node", MODIFICATION_GROUP_UUID_2, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); createNode(root.getStudyId(), root, node1, userId); - root = getRootNode(root.getStudyId()); + root = getRootNode(root.getStudyId(), firstRootNetworkUuid); List children = root.getChildren(); assertEquals(1, children.size()); NetworkModificationNode networkModificationNode = (NetworkModificationNode) children.get(0); @@ -541,8 +553,8 @@ private UUID createNodeTree() throws Exception { @Test void testNodeModificationInfos() throws Exception { UUID rootStudyId = createNodeTree(); - UUID rootNetworkUuid = rootNetworkRepository.findAllByStudyId(rootStudyId).stream().findFirst().orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)).getId(); - RootNode root = getRootNode(rootStudyId); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(rootStudyId); + RootNode root = getRootNode(rootStudyId, firstRootNetworkUuid); UUID rootId = root.getId(); RootNodeInfoEntity rootInfos = rootNodeInfoRepository.findById(rootId).orElseThrow(() -> new StudyException(StudyException.Type.NODE_NOT_FOUND)); @@ -552,7 +564,7 @@ void testNodeModificationInfos() throws Exception { assertEquals(2, children.size()); NetworkModificationNode n1 = (NetworkModificationNode) children.get(0); NetworkModificationNodeInfoEntity n1Infos = networkModificationTreeService.getNetworkModificationNodeInfoEntity(n1.getId()); - RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(n1.getId(), rootNetworkUuid).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); + RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoRepository.findByNodeInfoIdAndRootNetworkId(n1.getId(), firstRootNetworkUuid).orElseThrow(() -> new StudyException(StudyException.Type.ROOT_NETWORK_NOT_FOUND)); assertEquals("n1", n1.getName()); assertEquals("zzz", n1.getDescription()); @@ -601,7 +613,8 @@ void testNodeManipulation() throws Exception { final NetworkModificationNode node4 = buildNetworkModificationNode("hypo 2", "potamus", MODIFICATION_GROUP_UUID_3, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); createNode(root.getStudyId(), root, node1, userId); createNode(root.getStudyId(), root, node2, userId); - root = getRootNode(root.getStudyId()); + UUID firstRootNetwork = studyTestUtils.getStudyFirstRootNetworkUuid(root.getStudyId()); + root = getRootNode(root.getStudyId(), firstRootNetwork); List children = root.getChildren(); /* expected : @@ -625,7 +638,7 @@ void testNodeManipulation() throws Exception { node(condriak) node(niark) */ - root = getRootNode(root.getStudyId()); + root = getRootNode(root.getStudyId(), firstRootNetwork); AbstractNode child; if (root.getChildren().get(0).getName().equals(children.get(1).getName())) { child = root.getChildren().get(0); @@ -643,7 +656,7 @@ void testNodeManipulation() throws Exception { node node node */ - root = getRootNode(root.getStudyId()); + root = getRootNode(root.getStudyId(), firstRootNetwork); assertEquals(3, root.getChildren().size()); child = root.getChildren().get(0); createNode(root.getStudyId(), child, node4, userId); @@ -655,7 +668,7 @@ void testNodeManipulation() throws Exception { | node */ - root = getRootNode(root.getStudyId()); + root = getRootNode(root.getStudyId(), firstRootNetwork); assertEquals(2, root.getChildren().size()); assertEquals(3, nodeRepository.findAll().size()); @@ -827,6 +840,7 @@ void testInsertAfter() throws Exception { void testNodeUpdate() throws Exception { String userId = "userId"; RootNode root = createRoot(); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(root.getStudyId()); final NetworkModificationNode node1 = buildNetworkModificationNode("hypo", "potamus", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); createNode(root.getStudyId(), root, node1, userId); node1.setName("grunt"); @@ -840,7 +854,7 @@ void testNodeUpdate() throws Exception { .andExpect(status().isOk()); checkElementUpdatedMessageSent(root.getStudyId(), userId); - root = getRootNode(root.getStudyId()); + root = getRootNode(root.getStudyId(), firstRootNetworkUuid); assertEquals(1, root.getChildren().size()); assertNodeEquals(node1, root.getChildren().get(0)); @@ -865,7 +879,7 @@ void testNodeUpdate() throws Exception { assertEquals(NODE_RENAMED, output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION).getHeaders().get(HEADER_UPDATE_TYPE)); checkElementUpdatedMessageSent(root.getStudyId(), userId); - var newNode = getNode(root.getStudyId(), node1.getId()); + var newNode = getNode(root.getStudyId(), node1.getId(), firstRootNetworkUuid); node1.setName(justANameUpdate.getName()); assertNodeEquals(node1, newNode); @@ -1082,7 +1096,7 @@ private StudyEntity insertDummyStudy() { private RootNode createRoot() { var study = insertDummyStudy(); AtomicReference result = new AtomicReference<>(); - result.set(networkModificationTreeService.getStudyTree(study.getId())); + result.set(networkModificationTreeService.getStudyTree(study.getId(), null)); return result.get(); } diff --git a/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java b/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java index 5d19e35b9..87506f314 100644 --- a/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java +++ b/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java @@ -411,7 +411,7 @@ void testResetUuidResultWhenNonEvacuatedEnergyFailed() throws Exception { UUID resultUuid = UUID.randomUUID(); StudyEntity studyEntity = insertDummyStudy(UUID.randomUUID(), UUID.randomUUID()); UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); - RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId()); + RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId(), null); NetworkModificationNode modificationNode = createNetworkModificationNode(studyEntity.getId(), rootNode.getId(), UUID.randomUUID(), VARIANT_ID, "node 1"); String resultUuidJson = objectMapper.writeValueAsString(new NodeReceiver(modificationNode.getId(), rootNetworkUuid)); diff --git a/src/test/java/org/gridsuite/study/server/RootNetworkTest.java b/src/test/java/org/gridsuite/study/server/RootNetworkTest.java index 61f2dd7e7..299688dfe 100644 --- a/src/test/java/org/gridsuite/study/server/RootNetworkTest.java +++ b/src/test/java/org/gridsuite/study/server/RootNetworkTest.java @@ -102,6 +102,7 @@ class RootNetworkTest { private static final String NEW_CASE_NAME = "newCaseName"; private static final String NEW_CASE_FORMAT = "newCaseFormat"; private static final UUID NEW_REPORT_UUID = UUID.randomUUID(); + private static final UUID DUPLICATE_CASE_UUID = UUID.randomUUID(); private static final String NODE_1_NAME = "node1"; private static final String NODE_2_NAME = "node2"; @@ -185,6 +186,7 @@ void testCreateRootNetworkRequest() throws Exception { importParameters.put("param2", "value2"); UUID stubId = wireMockServer.stubFor(WireMock.post(WireMock.urlPathEqualTo("/v1/networks")) .willReturn(WireMock.ok())).getId(); + Mockito.doReturn(DUPLICATE_CASE_UUID).when(caseService).duplicateCase(caseUuid, true); // request execution - returns RootNetworkCreationRequestInfos String response = mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks?caseUuid={caseUuid}&caseFormat={caseFormat}", studyEntity.getId(), caseUuid, caseFormat) @@ -197,7 +199,7 @@ void testCreateRootNetworkRequest() throws Exception { wireMockUtils.verifyPostRequest(stubId, "/v1/networks", false, - Map.of("caseUuid", WireMock.equalTo(caseUuid.toString()), + Map.of("caseUuid", WireMock.equalTo(DUPLICATE_CASE_UUID.toString()), "caseFormat", WireMock.equalTo(caseFormat), "receiver", WireMock.matching(".*rootNetworkUuid.*")), objectMapper.writeValueAsString(importParameters) @@ -233,6 +235,7 @@ void testCreateRootNetworkRequestWithError() throws Exception { String caseFormat = "newCaseFormat"; UUID stubId = wireMockServer.stubFor(WireMock.post(WireMock.urlPathEqualTo("/v1/networks")) .willReturn(WireMock.serverError().withBody("Error when creating root network"))).getId(); + Mockito.doReturn(DUPLICATE_CASE_UUID).when(caseService).duplicateCase(caseUuid, true); // request execution - returns RootNetworkCreationRequestInfos mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks?caseUuid={caseUuid}&caseFormat={caseFormat}", studyEntity.getId(), caseUuid, caseFormat) @@ -242,12 +245,13 @@ void testCreateRootNetworkRequestWithError() throws Exception { wireMockUtils.verifyPostRequest(stubId, "/v1/networks", false, - Map.of("caseUuid", WireMock.equalTo(caseUuid.toString()), + Map.of("caseUuid", WireMock.equalTo(DUPLICATE_CASE_UUID.toString()), "caseFormat", WireMock.equalTo(caseFormat), "receiver", WireMock.matching(".*rootNetworkUuid.*")), null ); + Mockito.verify(caseService, Mockito.times(1)).duplicateCase(caseUuid, true); // check no rootNetworkCreationRequest has been saved assertEquals(0, rootNetworkCreationRequestRepository.count()); } @@ -375,7 +379,9 @@ void testDeleteRootNetwork() throws Exception { // before deletion, check we have 2 root networks for study assertEquals(2, rootNetworkService.getStudyRootNetworks(studyEntity.getId()).size()); - mockMvc.perform(delete("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}", studyEntity.getId(), rootNetworkEntityToDelete.getId()) + mockMvc.perform(delete("/v1/studies/{studyUuid}/root-networks", studyEntity.getId()) + .contentType(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(List.of(rootNetworkEntityToDelete.getId()))) .header("userId", USER_ID)) .andExpect(status().isOk()); diff --git a/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java b/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java index cf11da990..db0afb485 100644 --- a/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java +++ b/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java @@ -398,7 +398,7 @@ void testResetUuidResultWhenSAFailed() throws Exception { UUID resultUuid = UUID.randomUUID(); StudyEntity studyEntity = insertDummyStudy(UUID.randomUUID(), UUID.randomUUID(), null); UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); - RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId()); + RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId(), null); NetworkModificationNode modificationNode = createNetworkModificationNode(studyEntity.getId(), rootNode.getId(), UUID.randomUUID(), VARIANT_ID, "node 1"); String resultUuidJson = objectMapper.writeValueAsString(new NodeReceiver(modificationNode.getId(), rootNetworkUuid)); diff --git a/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java b/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java index 28dcfb5e7..40dd72fe9 100644 --- a/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java +++ b/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java @@ -523,7 +523,7 @@ void testResetUuidResultWhenSAFailed() throws Exception { UUID resultUuid = UUID.randomUUID(); StudyEntity studyEntity = insertDummyStudy(UUID.randomUUID(), UUID.randomUUID(), SENSITIVITY_ANALYSIS_PARAMETERS_UUID); UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyEntity.getId()); - RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId()); + RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId(), null); NetworkModificationNode modificationNode = createNetworkModificationNode(studyEntity.getId(), rootNode.getId(), UUID.randomUUID(), VARIANT_ID, "node 1"); String resultUuidJson = objectMapper.writeValueAsString(new NodeReceiver(modificationNode.getId(), firstRootNetworkUuid)); diff --git a/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java b/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java index 45d18c87b..29aa16c1c 100644 --- a/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java +++ b/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java @@ -625,7 +625,7 @@ void testResetUuidResultWhenSCFailed() throws Exception { UUID resultUuid = UUID.randomUUID(); StudyEntity studyEntity = insertDummyStudy(UUID.randomUUID(), UUID.randomUUID(), null); UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); - RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId()); + RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId(), null); NetworkModificationNode modificationNode = createNetworkModificationNode(studyEntity.getId(), rootNode.getId(), UUID.randomUUID(), VARIANT_ID, "node 1"); String resultUuidJson = objectMapper.writeValueAsString(new NodeReceiver(modificationNode.getId(), rootNetworkUuid)); diff --git a/src/test/java/org/gridsuite/study/server/StudyTest.java b/src/test/java/org/gridsuite/study/server/StudyTest.java index 1a00baa1c..384158bc8 100644 --- a/src/test/java/org/gridsuite/study/server/StudyTest.java +++ b/src/test/java/org/gridsuite/study/server/StudyTest.java @@ -36,6 +36,7 @@ import org.gridsuite.study.server.dto.elasticsearch.EquipmentInfos; import org.gridsuite.study.server.dto.modification.ModificationInfos; import org.gridsuite.study.server.dto.modification.ModificationType; +import org.gridsuite.study.server.dto.modification.MultipleNetworkModificationsInfos; import org.gridsuite.study.server.elasticsearch.EquipmentInfosService; import org.gridsuite.study.server.elasticsearch.StudyInfosService; import org.gridsuite.study.server.networkmodificationtree.dto.*; @@ -997,8 +998,9 @@ void testLogsReport(final MockWebServer server) throws Exception { void testGetNodeReportLogs(final MockWebServer server) throws Exception { UUID studyUuid = createStudy(server, "userId", CASE_UUID); UUID rootNodeUuid = getRootNodeUuid(studyUuid); + UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); - MvcResult mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/report/{reportId}/logs", studyUuid, rootNodeUuid, REPORT_ID).header(USER_ID_HEADER, "userId")) + MvcResult mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/report/{reportId}/logs", studyUuid, firstRootNetworkUuid, rootNodeUuid, REPORT_ID).header(USER_ID_HEADER, "userId")) .andExpect(status().isOk()).andReturn(); String resultAsString = mvcResult.getResponse().getContentAsString(); List reportLogs = mapper.readValue(resultAsString, new TypeReference>() { }); @@ -1007,7 +1009,7 @@ void testGetNodeReportLogs(final MockWebServer server) throws Exception { assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/reports/" + REPORT_ID + "/logs"))); //test with severityFilter and messageFilter param - mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/report/{reportId}/logs?severityLevels=WARN&message=testMsgFilter", studyUuid, rootNodeUuid, REPORT_ID).header(USER_ID_HEADER, "userId")) + mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/report/{reportId}/logs?severityLevels=WARN&message=testMsgFilter", studyUuid, firstRootNetworkUuid, rootNodeUuid, REPORT_ID).header(USER_ID_HEADER, "userId")) .andExpect(status().isOk()).andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); reportLogs = mapper.readValue(resultAsString, new TypeReference>() { }); @@ -1021,7 +1023,7 @@ void testGetParentNodesReportLogs(final MockWebServer server) throws Exception { String userId = "userId"; UUID studyUuid = createStudy(server, userId, CASE_UUID); UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid); - RootNode rootNode = networkModificationTreeService.getStudyTree(studyUuid); + RootNode rootNode = networkModificationTreeService.getStudyTree(studyUuid, null); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); AbstractNode modificationNode = rootNode.getChildren().get(0); NetworkModificationNode node1 = createNetworkModificationNode(studyUuid, modificationNodeUuid, VARIANT_ID, "node1", userId); @@ -1531,7 +1533,7 @@ void testCreateStudyWithDefaultVoltageInitUserHasValidParamsInProfile(final Mock private void testDuplicateStudy(final MockWebServer mockWebServer, UUID study1Uuid, UUID rootNetworkUuid) throws Exception { String userId = "userId"; - RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); + RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid, null); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); NetworkModificationNode node2 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID_2, "node2", userId); @@ -1539,7 +1541,9 @@ private void testDuplicateStudy(final MockWebServer mockWebServer, UUID study1Uu // add modification on node "node1" String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; - UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId(), rootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(createTwoWindingsTransformerAttributes) @@ -1550,12 +1554,15 @@ private void testDuplicateStudy(final MockWebServer mockWebServer, UUID study1Uu checkUpdateModelsStatusMessagesReceived(study1Uuid, node1.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node1.getId()); checkElementUpdatedMessageSent(study1Uuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createTwoWindingsTransformerAttributes); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(rootNetworkUuid, node1.getId(), NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // add modification on node "node2" String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; - stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId(), rootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(createLoadAttributes) @@ -1566,7 +1573,9 @@ private void testDuplicateStudy(final MockWebServer mockWebServer, UUID study1Uu checkUpdateModelsStatusMessagesReceived(study1Uuid, node2.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node2.getId()); checkElementUpdatedMessageSent(study1Uuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createLoadAttributes); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(rootNetworkUuid, node2.getId(), NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); rootNetworkNodeInfoService.updateRootNetworkNode(node2.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid), RootNetworkNodeInfo.builder() @@ -1681,7 +1690,7 @@ private StudyEntity duplicateStudy(final MockWebServer server, UUID studyUuid) t StudyEntity duplicatedStudy = studyRepository.findById(UUID.fromString(newUuid)).orElse(null); assertNotNull(duplicatedStudy); - RootNode duplicatedRootNode = networkModificationTreeService.getStudyTree(UUID.fromString(newUuid)); + RootNode duplicatedRootNode = networkModificationTreeService.getStudyTree(UUID.fromString(newUuid), null); assertNotNull(duplicatedRootNode); //Check tree node has been duplicated @@ -1774,7 +1783,7 @@ void testCutAndPasteNode(final MockWebServer mockWebServer) throws Exception { String userId = "userId"; UUID study1Uuid = createStudy(mockWebServer, "userId", CASE_UUID); UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid); - RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); + RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid, null); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); NetworkModificationNode node2 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID_2, "node2", userId); @@ -1791,7 +1800,10 @@ void testCutAndPasteNode(final MockWebServer mockWebServer) throws Exception { // add modification on node "node1" String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; - UUID stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId(), firstRootNetworkUuid) .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -1801,11 +1813,14 @@ void testCutAndPasteNode(final MockWebServer mockWebServer) throws Exception { checkUpdateModelsStatusMessagesReceived(study1Uuid, node1.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node1.getId()); checkElementUpdatedMessageSent(study1Uuid, userId); - wireMockUtils.verifyNetworkModificationPost(stubUuid, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createTwoWindingsTransformerAttributes); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, node1.getId(), NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // add modification on node "node2" String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; - stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId(), firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(createLoadAttributes) @@ -1816,7 +1831,9 @@ void testCutAndPasteNode(final MockWebServer mockWebServer) throws Exception { checkUpdateModelsStatusMessagesReceived(study1Uuid, node2.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node2.getId()); checkElementUpdatedMessageSent(study1Uuid, userId); - wireMockUtils.verifyNetworkModificationPost(stubUuid, createLoadAttributes, NETWORK_UUID_STRING); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createLoadAttributes); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, node2.getId(), NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); rootNetworkNodeInfoService.updateRootNetworkNode(node2.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid), RootNetworkNodeInfo.builder() @@ -1929,7 +1946,7 @@ void testCutAndPasteNode(final MockWebServer mockWebServer) throws Exception { void testCutAndPasteNodeAroundItself(final MockWebServer mockWebServer) throws Exception { String userId = "userId"; UUID study1Uuid = createStudy(mockWebServer, userId, CASE_UUID); - RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); + RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid, null); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); @@ -1965,7 +1982,7 @@ void testCutAndPasteNodeWithoutModification(final MockWebServer server) throws E String userId = "userId"; UUID study1Uuid = createStudy(server, userId, CASE_UUID); UUID rootNetworkUuid = rootNetworkRepository.findAllByStudyId(study1Uuid).stream().findFirst().orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)).getId(); - RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); + RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid, null); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, UUID.randomUUID(), VARIANT_ID, "node1", BuildStatus.BUILT, userId); @@ -1987,7 +2004,7 @@ void testCutAndPasteNodeWithModification(final MockWebServer server) throws Exce String userId = "userId"; UUID study1Uuid = createStudy(server, userId, CASE_UUID); UUID rootNetworkUuid = rootNetworkRepository.findAllByStudyId(study1Uuid).stream().findFirst().orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)).getId(); - RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); + RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid, null); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, UUID.randomUUID(), VARIANT_ID, "node1", BuildStatus.BUILT, userId); @@ -2008,7 +2025,7 @@ void testCutAndPasteNodeWithModification(final MockWebServer server) throws Exce void testCutAndPastErrors(final MockWebServer mockWebServer) throws Exception { String userId = "userId"; UUID study1Uuid = createStudy(mockWebServer, "userId", CASE_UUID); - RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); + RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid, null); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); @@ -2042,7 +2059,7 @@ void testCutAndPasteSubtree(final MockWebServer server) throws Exception { String userId = "userId"; UUID study1Uuid = createStudy(server, userId, CASE_UUID); UUID rootNetworkUuid = rootNetworkRepository.findAllByStudyId(study1Uuid).stream().findFirst().orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND)).getId(); - RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); + RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid, null); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, UUID.randomUUID(), VARIANT_ID, "node1", BuildStatus.BUILT, userId); @@ -2108,7 +2125,7 @@ void testDuplicateNode(final MockWebServer mockWebServer) throws Exception { String userId = "userId"; UUID study1Uuid = createStudy(mockWebServer, userId, CASE_UUID); UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid); - RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); + RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid, null); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); NetworkModificationNode node2 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID_2, "node2", userId); @@ -2117,7 +2134,9 @@ void testDuplicateNode(final MockWebServer mockWebServer) throws Exception { // add modification on node "node1" String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; - UUID stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId(), firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(createTwoWindingsTransformerAttributes) @@ -2128,11 +2147,14 @@ void testDuplicateNode(final MockWebServer mockWebServer) throws Exception { checkUpdateModelsStatusMessagesReceived(study1Uuid, node1.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node1.getId()); checkElementUpdatedMessageSent(study1Uuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubUuid, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createTwoWindingsTransformerAttributes); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, node1.getId(), NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // add modification on node "node2" String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; - stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId(), firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(createLoadAttributes) @@ -2143,7 +2165,9 @@ void testDuplicateNode(final MockWebServer mockWebServer) throws Exception { checkUpdateModelsStatusMessagesReceived(study1Uuid, node2.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node2.getId()); checkElementUpdatedMessageSent(study1Uuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubUuid, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createLoadAttributes); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, node2.getId(), NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); rootNetworkNodeInfoService.updateRootNetworkNode(node2.getId(), studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid), RootNetworkNodeInfo.builder() @@ -2223,7 +2247,7 @@ void testDuplicateSubtree(final MockWebServer server) throws Exception { String userId = "userId"; UUID study1Uuid = createStudy(server, userId, CASE_UUID); UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid); - RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); + RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid, null); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); NetworkModificationNode node2 = createNetworkModificationNode(study1Uuid, node1.getId(), VARIANT_ID_2, "node2", userId); @@ -2241,7 +2265,9 @@ void testDuplicateSubtree(final MockWebServer server) throws Exception { // add modification on node "node1" (not built) -> invalidation of node 3 String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; - UUID stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId(), firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(createTwoWindingsTransformerAttributes) @@ -2252,7 +2278,9 @@ void testDuplicateSubtree(final MockWebServer server) throws Exception { checkUpdateModelsStatusMessagesReceived(study1Uuid, node1.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node1.getId()); checkElementUpdatedMessageSent(study1Uuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubUuid, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createTwoWindingsTransformerAttributes); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, node1.getId(), NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // Invalidation node 3 assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(node3.getId(), firstRootNetworkUuid).getGlobalBuildStatus()); @@ -2261,7 +2289,8 @@ void testDuplicateSubtree(final MockWebServer server) throws Exception { // add modification on node "node2" String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; - stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId(), firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) .content(createLoadAttributes) @@ -2272,7 +2301,9 @@ void testDuplicateSubtree(final MockWebServer server) throws Exception { checkUpdateModelsStatusMessagesReceived(study1Uuid, node2.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node2.getId()); checkElementUpdatedMessageSent(study1Uuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubUuid, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createLoadAttributes); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, node2.getId(), NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); rootNetworkNodeInfoService.updateRootNetworkNode(node2.getId(), firstRootNetworkUuid, RootNetworkNodeInfo.builder() @@ -2368,18 +2399,20 @@ void testDuplicateNodeBetweenStudies(final MockWebServer mockWebServer) throws E String userId = "userId"; UUID study1Uuid = createStudy(mockWebServer, userId, CASE_UUID); UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(study1Uuid); - RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); + RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid, null); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); NetworkModificationNode node2 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID_2, "node2", userId); UUID study2Uuid = createStudy(mockWebServer, userId, CASE_UUID); - RootNode study2RootNode = networkModificationTreeService.getStudyTree(study2Uuid); + RootNode study2RootNode = networkModificationTreeService.getStudyTree(study2Uuid, null); UUID study2ModificationNodeUuid = study2RootNode.getChildren().get(0).getId(); NetworkModificationNode study2Node2 = createNetworkModificationNode(study2Uuid, study2ModificationNodeUuid, VARIANT_ID_2, "node2", userId); // add modification on study 1 node "node1" - UUID stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + Optional modificationUuid = Optional.of(UUID.randomUUID()); + UUID stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + UUID stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId(), firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) @@ -2391,10 +2424,13 @@ void testDuplicateNodeBetweenStudies(final MockWebServer mockWebServer) throws E checkUpdateModelsStatusMessagesReceived(study1Uuid, node1.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node1.getId()); checkElementUpdatedMessageSent(study1Uuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubUuid, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING, VARIANT_ID); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createTwoWindingsTransformerAttributes); + MultipleNetworkModificationsInfos applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, node1.getId(), NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); // add modification on node "node2" - stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); + stubPostWithoutApplyingId = wireMockUtils.stubNetworkModificationPostWithoutApplying(mapper.writeValueAsString(modificationUuid)); + stubPostId = wireMockUtils.stubNetworkModificationPostApply(mapper.writeValueAsString(Optional.empty())); String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId(), firstRootNetworkUuid) .contentType(MediaType.APPLICATION_JSON) @@ -2406,7 +2442,9 @@ void testDuplicateNodeBetweenStudies(final MockWebServer mockWebServer) throws E checkUpdateModelsStatusMessagesReceived(study1Uuid, node2.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node2.getId()); checkElementUpdatedMessageSent(study1Uuid, userId); - wireMockUtils.verifyNetworkModificationPostWithVariant(stubUuid, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); + wireMockUtils.verifyNetworkModificationPostWithoutApplying(stubPostWithoutApplyingId, createLoadAttributes); + applyModificationBody = new MultipleNetworkModificationsInfos(List.of(modificationUuid.get()), List.of(rootNetworkNodeInfoService.getNetworkModificationContextInfos(firstRootNetworkUuid, node2.getId(), NETWORK_UUID))); + wireMockUtils.verifyNetworkModificationApplyWithVariant(stubPostId, mapper.writeValueAsString(applyModificationBody)); //study 2 node2 should not have any child List allNodes = networkModificationTreeService.getAllNodes(study2Uuid); diff --git a/src/test/java/org/gridsuite/study/server/SupervisionControllerTest.java b/src/test/java/org/gridsuite/study/server/SupervisionControllerTest.java index 0c8eaa3fa..f8a1f4723 100644 --- a/src/test/java/org/gridsuite/study/server/SupervisionControllerTest.java +++ b/src/test/java/org/gridsuite/study/server/SupervisionControllerTest.java @@ -31,10 +31,12 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; @@ -43,6 +45,8 @@ import java.util.UUID; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -81,7 +85,7 @@ class SupervisionControllerTest { @Autowired private ObjectMapper mapper; - @MockBean + @SpyBean private RootNetworkService rootNetworkService; @Autowired @@ -89,9 +93,13 @@ class SupervisionControllerTest { @Autowired private RestClient restClient; + @Autowired private StudyTestUtils studyTestUtils; + @MockBean + private NetworkService networkService; + private static EquipmentInfos toEquipmentInfos(Identifiable i) { return EquipmentInfos.builder() .networkUuid(SupervisionControllerTest.NETWORK_UUID) @@ -120,7 +128,7 @@ void setup() { //TODO: removing it still works, check if it's normal // when(networkModificationTreeService.getVariantId(NODE_UUID, any())).thenReturn(VariantManagerConstants.INITIAL_VARIANT_ID); - when(networkModificationTreeService.getStudyTree(STUDY_UUID)).thenReturn(RootNode.builder().studyId(STUDY_UUID).id(NODE_UUID).build()); + when(networkModificationTreeService.getStudyTree(STUDY_UUID, null)).thenReturn(RootNode.builder().studyId(STUDY_UUID).id(NODE_UUID).build()); when(networkConversionService.checkStudyIndexationStatus(NETWORK_UUID)).thenReturn(true); } @@ -217,12 +225,14 @@ void testDeleteIndexation() throws Exception { void testInvalidateAllNodesBuilds() throws Exception { initStudy(); + Mockito.doNothing().when(networkService).deleteVariants(eq(NETWORK_UUID), any()); + mockMvc.perform(delete("/v1/supervision/studies/{studyUuid}/nodes/builds", STUDY_UUID)) .andExpect(status().isOk()); assertIndexationCount(74, 0); assertIndexationStatus(STUDY_UUID, StudyIndexationStatus.INDEXED.name()); - + Mockito.verify(networkService, Mockito.times(1)).deleteVariants(eq(NETWORK_UUID), any()); } @Test diff --git a/src/test/java/org/gridsuite/study/server/VoltageInitTest.java b/src/test/java/org/gridsuite/study/server/VoltageInitTest.java index e63d539d6..75e9b56c2 100644 --- a/src/test/java/org/gridsuite/study/server/VoltageInitTest.java +++ b/src/test/java/org/gridsuite/study/server/VoltageInitTest.java @@ -734,7 +734,7 @@ void testNotResetedUuidResultWhenVoltageInitFailed() throws Exception { UUID resultUuid = UUID.randomUUID(); StudyEntity studyEntity = insertDummyStudy(UUID.randomUUID(), UUID.randomUUID(), UUID.fromString(VOLTAGE_INIT_PARAMETERS_UUID_STRING), false); UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId(); - RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId()); + RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId(), null); NetworkModificationNode modificationNode = createNetworkModificationNode(studyEntity.getId(), rootNode.getId(), UUID.randomUUID(), VARIANT_ID, "node 1"); String resultUuidJson = objectMapper.writeValueAsString(new NodeReceiver(modificationNode.getId(), rootNetworkUuid)); diff --git a/src/test/java/org/gridsuite/study/server/service/ReportServiceTest.java b/src/test/java/org/gridsuite/study/server/service/ReportServiceTest.java index 999616ae9..582f0217f 100644 --- a/src/test/java/org/gridsuite/study/server/service/ReportServiceTest.java +++ b/src/test/java/org/gridsuite/study/server/service/ReportServiceTest.java @@ -156,7 +156,7 @@ private RootNode createRoot() { StudyEntity studyEntity = TestUtils.createDummyStudy(UUID.randomUUID(), UUID.randomUUID(), "caseName", "", ROOT_NODE_REPORT_UUID); studyRepository.save(studyEntity); networkModificationTreeService.createRoot(studyEntity); - return networkModificationTreeService.getStudyTree(studyEntity.getId()); + return networkModificationTreeService.getStudyTree(studyEntity.getId(), null); } @Test diff --git a/src/test/java/org/gridsuite/study/server/utils/StudyTestUtils.java b/src/test/java/org/gridsuite/study/server/utils/StudyTestUtils.java index dd88451ba..29d1862c1 100644 --- a/src/test/java/org/gridsuite/study/server/utils/StudyTestUtils.java +++ b/src/test/java/org/gridsuite/study/server/utils/StudyTestUtils.java @@ -2,7 +2,6 @@ import org.gridsuite.study.server.repository.rootnetwork.RootNetworkRepository; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import java.util.UUID; @@ -14,7 +13,6 @@ public StudyTestUtils(RootNetworkRepository rootNetworkRepository) { this.rootNetworkRepository = rootNetworkRepository; } - @Transactional public UUID getStudyFirstRootNetworkUuid(UUID studyUuid) { return rootNetworkRepository.findAllByStudyId(studyUuid).get(0).getId(); } diff --git a/src/test/java/org/gridsuite/study/server/utils/WireMockUtils.java b/src/test/java/org/gridsuite/study/server/utils/WireMockUtils.java index b25250dbd..aa85db7f8 100644 --- a/src/test/java/org/gridsuite/study/server/utils/WireMockUtils.java +++ b/src/test/java/org/gridsuite/study/server/utils/WireMockUtils.java @@ -144,7 +144,7 @@ public UUID stubNetworkModificationCountGet(String groupUuid, Integer expectedCo ).getId(); } - public UUID stubNetworkModificationPost(String responseBody) { + public UUID stubNetworkModificationPostWithoutApplying(String responseBody) { return wireMock.stubFor(WireMock.post(WireMock.urlPathEqualTo(URI_NETWORK_MODIFICATION)) .willReturn(WireMock.ok() .withBody(responseBody) @@ -152,6 +152,14 @@ public UUID stubNetworkModificationPost(String responseBody) { ).getId(); } + public UUID stubNetworkModificationPostApply(String responseBody) { + return wireMock.stubFor(WireMock.post(WireMock.urlPathEqualTo(URI_NETWORK_MODIFICATION + DELIMITER + "apply")) + .willReturn(WireMock.ok() + .withBody(responseBody) + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)) + ).getId(); + } + public UUID stubNetworkModificationPostWithError(String requestBody) { return stubNetworkModificationPostWithError(requestBody, "Internal Server Error"); } @@ -208,15 +216,21 @@ public void verifyNetworkModificationCountsGet(UUID stubId, String groupUuid) { verifyGetRequest(stubId, URI_NETWORK_MODIFICATION_GROUPS + DELIMITER + groupUuid + "/network-modifications-count", Map.of(QUERY_PARAM_STASHED, WireMock.equalTo("false"))); } - public void verifyNetworkModificationPost(UUID stubId, String requestBody, String networkUuid) { + public void verifyNetworkModificationPost(UUID stubId, String requestBody) { verifyPostRequest(stubId, URI_NETWORK_MODIFICATION, false, - Map.of("networkUuid", WireMock.equalTo(networkUuid), "groupUuid", WireMock.matching(".*")), + Map.of("groupUuid", WireMock.matching(".*")), requestBody); } - public void verifyNetworkModificationPostWithVariant(UUID stubId, String requestBody, String networkUuid, String variantId) { + public void verifyNetworkModificationPostWithoutApplying(UUID stubId, String requestBody) { verifyPostRequest(stubId, URI_NETWORK_MODIFICATION, false, - Map.of("networkUuid", WireMock.equalTo(networkUuid), "groupUuid", WireMock.matching(".*"), "variantId", WireMock.equalTo(variantId)), + Map.of(), + requestBody); + } + + public void verifyNetworkModificationApplyWithVariant(UUID stubId, String requestBody) { + verifyPostRequest(stubId, URI_NETWORK_MODIFICATION + DELIMITER + "apply", false, + Map.of(), requestBody); } From 92c524174808e849c3c1790684d43e2cfda28f9b Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Wed, 8 Jan 2025 11:41:18 +0100 Subject: [PATCH 15/17] fix: sonar issues Signed-off-by: LE SAULNIER Kevin --- .../study/server/service/ConsumerService.java | 11 +++++------ .../gridsuite/study/server/service/StudyService.java | 7 +++---- .../study/server/service/SupervisionService.java | 1 - .../study/server/NetworkModificationTest.java | 1 - 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/service/ConsumerService.java b/src/main/java/org/gridsuite/study/server/service/ConsumerService.java index 0bbfb7adf..62e0cae68 100644 --- a/src/main/java/org/gridsuite/study/server/service/ConsumerService.java +++ b/src/main/java/org/gridsuite/study/server/service/ConsumerService.java @@ -395,12 +395,11 @@ public Consumer> consumeCaseImportFailed() { UUID studyUuid = receiver.getStudyUuid(); String userId = receiver.getUserId(); - switch (receiver.getCaseImportAction()) { - case STUDY_CREATION -> { - studyService.deleteStudyIfNotCreationInProgress(studyUuid, userId); - notificationService.emitStudyCreationError(studyUuid, userId, errorMessage); - } - case ROOT_NETWORK_CREATION, ROOT_NETWORK_MODIFICATION -> notificationService.emitRootNetworksUpdateFailed(studyUuid, errorMessage); + if (receiver.getCaseImportAction() == CaseImportAction.STUDY_CREATION) { + studyService.deleteStudyIfNotCreationInProgress(studyUuid, userId); + notificationService.emitStudyCreationError(studyUuid, userId, errorMessage); + } else { + notificationService.emitRootNetworksUpdateFailed(studyUuid, errorMessage); } } catch (Exception e) { LOGGER.error(e.toString(), e); diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index 40812a2a9..37e692f9e 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -393,9 +393,9 @@ public void duplicateStudyAsync(BasicStudyInfos basicStudyInfos, UUID sourceStud StudyEntity duplicatedStudy = duplicateStudy(basicStudyInfos, sourceStudyUuid, userId); - rootNetworkService.getStudyRootNetworks(duplicatedStudy.getId()).forEach(rootNetworkEntity -> { - reindexStudy(duplicatedStudy, rootNetworkEntity.getId()); - }); + rootNetworkService.getStudyRootNetworks(duplicatedStudy.getId()).forEach(rootNetworkEntity -> + reindexStudy(duplicatedStudy, rootNetworkEntity.getId()) + ); } catch (Exception e) { LOGGER.error(e.toString(), e); } finally { @@ -1495,7 +1495,6 @@ public void duplicateStudySubtree(UUID sourceStudyUuid, UUID targetStudyUuid, UU checkStudyContainsNode(targetStudyUuid, referenceNodeUuid); StudyEntity studyEntity = studyRepository.findById(targetStudyUuid).orElseThrow(() -> new StudyException(STUDY_NOT_FOUND)); - //TODO: tofix, should not have rootNetworkUuid here, but this method returns data linked to a specific root network AbstractNode studySubTree = networkModificationTreeService.getStudySubtree(sourceStudyUuid, parentNodeToCopyUuid, null); UUID duplicatedNodeUuid = networkModificationTreeService.cloneStudyTree(studySubTree, referenceNodeUuid, studyEntity); notificationService.emitSubtreeInserted(targetStudyUuid, duplicatedNodeUuid, referenceNodeUuid); diff --git a/src/main/java/org/gridsuite/study/server/service/SupervisionService.java b/src/main/java/org/gridsuite/study/server/service/SupervisionService.java index 418a6a78c..434a59a49 100644 --- a/src/main/java/org/gridsuite/study/server/service/SupervisionService.java +++ b/src/main/java/org/gridsuite/study/server/service/SupervisionService.java @@ -304,7 +304,6 @@ private Integer deleteStateEstimationResults() { public void invalidateAllNodesBuilds(UUID studyUuid) { AtomicReference startTime = new AtomicReference<>(); startTime.set(System.nanoTime()); - //TODO: to fix, should not have any root network uuid here UUID rootNodeUuid = networkModificationTreeService.getStudyRootNodeUuid(studyUuid); //TODO: to parallelize ? rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java index 28ea53f53..4f8589c42 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java @@ -227,7 +227,6 @@ class NetworkModificationTest { private UUID userNoProfileStubId; private static final String ERROR_MESSAGE = "nullPointerException: unexpected null somewhere"; - private ObjectMapper objectMapper; @BeforeEach void setup(final MockWebServer server) { From 8209f08ac12dc2840d2b1bd4087ee7be5318d170 Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Wed, 8 Jan 2025 14:15:51 +0100 Subject: [PATCH 16/17] feat: migrate new endpoint Signed-off-by: LE SAULNIER Kevin --- .../java/org/gridsuite/study/server/StudyController.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/StudyController.java b/src/main/java/org/gridsuite/study/server/StudyController.java index ef8c10ba2..0b6bb2fe8 100644 --- a/src/main/java/org/gridsuite/study/server/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/StudyController.java @@ -1116,22 +1116,26 @@ public ResponseEntity> getNodeReportLogs(@Parameter(description return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getReportLogs(reportId, messageFilter, severityLevels)); } - @GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/report/{reportId}/aggregated-severities", produces = MediaType.APPLICATION_JSON_VALUE) + @GetMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/report/{reportId}/aggregated-severities", produces = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Get node report severities") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The node report severities"), @ApiResponse(responseCode = "404", description = "The study/node is not found")}) public ResponseEntity> getNodeReportAggregatedSeverities(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid, + @Parameter(description = "root network id") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid, @Parameter(description = "node id") @PathVariable("nodeUuid") UUID nodeUuid, @Parameter(description = "reportId") @PathVariable("reportId") UUID reportId) { studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid); + rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkUuid); return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getNodeReportAggregatedSeverities(reportId)); } - @GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/report/aggregated-severities", produces = MediaType.APPLICATION_JSON_VALUE) + @GetMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/report/aggregated-severities", produces = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Get the report severities of the given node and all its parents") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The report severities of the node and all its parent"), @ApiResponse(responseCode = "404", description = "The study/node is not found")}) public ResponseEntity> getParentNodesAggregatedReportSeverities(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid, + @Parameter(description = "root network id") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid, @Parameter(description = "node id") @PathVariable("nodeUuid") UUID nodeUuid) { studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid); + rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkUuid); return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getParentNodesAggregatedReportSeverities(nodeUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid))); } From b2560f9568eb2456d3a235f622d6549eed36d8b6 Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Thu, 9 Jan 2025 10:23:23 +0100 Subject: [PATCH 17/17] fix: add controls around root network deletion Signed-off-by: LE SAULNIER Kevin --- .../RestResponseEntityExceptionHandler.java | 3 +- .../study/server/StudyController.java | 2 +- .../study/server/StudyException.java | 1 + .../study/server/service/StudyService.java | 13 ++++--- .../study/server/RootNetworkTest.java | 36 +++++++++++++++++++ 5 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/RestResponseEntityExceptionHandler.java b/src/main/java/org/gridsuite/study/server/RestResponseEntityExceptionHandler.java index 617385b33..94942fa12 100644 --- a/src/main/java/org/gridsuite/study/server/RestResponseEntityExceptionHandler.java +++ b/src/main/java/org/gridsuite/study/server/RestResponseEntityExceptionHandler.java @@ -61,7 +61,8 @@ protected ResponseEntity handleStudyException(StudyException exception) -> ResponseEntity.status(HttpStatus.FORBIDDEN).body(type); case NOT_ALLOWED, BAD_NODE_TYPE, - NODE_NAME_ALREADY_EXIST + NODE_NAME_ALREADY_EXIST, + ROOT_NETWORK_DELETE_FORBIDDEN -> ResponseEntity.status(HttpStatus.FORBIDDEN).body(exception.getMessage()); case CANT_DELETE_ROOT_NODE -> ResponseEntity.status(HttpStatus.FORBIDDEN).body(NOT_ALLOWED); case CREATE_NETWORK_MODIFICATION_FAILED, diff --git a/src/main/java/org/gridsuite/study/server/StudyController.java b/src/main/java/org/gridsuite/study/server/StudyController.java index 0b6bb2fe8..69e47c9ff 100644 --- a/src/main/java/org/gridsuite/study/server/StudyController.java +++ b/src/main/java/org/gridsuite/study/server/StudyController.java @@ -1115,7 +1115,7 @@ public ResponseEntity> getNodeReportLogs(@Parameter(description rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkUuid); return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getReportLogs(reportId, messageFilter, severityLevels)); } - + @GetMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/report/{reportId}/aggregated-severities", produces = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Get node report severities") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The node report severities"), @ApiResponse(responseCode = "404", description = "The study/node is not found")}) diff --git a/src/main/java/org/gridsuite/study/server/StudyException.java b/src/main/java/org/gridsuite/study/server/StudyException.java index 98cfc57a4..aa7473f1a 100644 --- a/src/main/java/org/gridsuite/study/server/StudyException.java +++ b/src/main/java/org/gridsuite/study/server/StudyException.java @@ -120,6 +120,7 @@ public enum Type { NETWORK_VISUALIZATION_PARAMETERS_NOT_FOUND, GET_NETWORK_VISUALIZATION_PARAMETERS_FAILED, ROOT_NETWORK_NOT_FOUND, + ROOT_NETWORK_DELETE_FORBIDDEN, ROOT_NETWORK_CREATION_FAILED } diff --git a/src/main/java/org/gridsuite/study/server/service/StudyService.java b/src/main/java/org/gridsuite/study/server/service/StudyService.java index f8bd5530e..d0f674a7d 100644 --- a/src/main/java/org/gridsuite/study/server/service/StudyService.java +++ b/src/main/java/org/gridsuite/study/server/service/StudyService.java @@ -285,11 +285,16 @@ public BasicStudyInfos createStudy(UUID caseUuid, String userId, UUID studyUuid, @Transactional public void deleteRootNetworks(UUID studyUuid, List rootNetworkUuids, String userId) { assertIsStudyExist(studyUuid); - rootNetworkUuids.forEach(rootNetworkUuid -> { - rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkUuid); + List rootNetworkEntities = rootNetworkService.getStudyRootNetworks(studyUuid); + if (rootNetworkUuids.size() >= rootNetworkEntities.size()) { + throw new StudyException(ROOT_NETWORK_DELETE_FORBIDDEN); + } + if (!rootNetworkEntities.stream().map(RootNetworkEntity::getId).collect(Collectors.toSet()).containsAll(rootNetworkUuids)) { + throw new StudyException(ROOT_NETWORK_NOT_FOUND); + } + + rootNetworkUuids.forEach(rootNetworkService::delete); - rootNetworkService.delete(rootNetworkUuid); - }); notificationService.emitRootNetworksUpdated(studyUuid); } diff --git a/src/test/java/org/gridsuite/study/server/RootNetworkTest.java b/src/test/java/org/gridsuite/study/server/RootNetworkTest.java index 299688dfe..444ecafa8 100644 --- a/src/test/java/org/gridsuite/study/server/RootNetworkTest.java +++ b/src/test/java/org/gridsuite/study/server/RootNetworkTest.java @@ -409,6 +409,42 @@ void testDeleteRootNetwork() throws Exception { Mockito.verify(loadFlowService, Mockito.times(1)).deleteLoadFlowResult(LOADFLOW_RESULT_UUID2); } + @Test + void testDeleteRootNetworkFailed() throws Exception { + // create study with one root node, two network modification node and a root network + StudyEntity studyEntity = TestUtils.createDummyStudy(NETWORK_UUID, CASE_UUID, CASE_NAME, CASE_FORMAT, REPORT_UUID); + studyRepository.save(studyEntity); + networkModificationTreeService.createRoot(studyEntity); + UUID firstRootNetworkUuid = rootNetworkService.getStudyRootNetworks(studyEntity.getId()).get(0).getId(); + + // create a second root network - will create a root network link between this and each node + RootNetworkEntity secondRootNetwork = rootNetworkService.createRootNetwork(studyEntity, RootNetworkInfos.builder() + .id(UUID.randomUUID()) + .importParameters(Map.of("param1", "value1", "param2", "value2")) + .caseInfos(new CaseInfos(CASE_UUID2, CASE_NAME2, CASE_FORMAT2)) + .networkInfos(new NetworkInfos(NETWORK_UUID2, NETWORK_ID2)) + .reportUuid(REPORT_UUID2) + .build()); + + // try to delete all root networks + mockMvc.perform(delete("/v1/studies/{studyUuid}/root-networks", studyEntity.getId()) + .contentType(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(List.of(firstRootNetworkUuid, secondRootNetwork.getId()))) + .header("userId", USER_ID)) + .andExpect(status().isForbidden()); + + assertEquals(2, rootNetworkService.getStudyRootNetworks(studyEntity.getId()).size()); + + // try to delete unknown root network + mockMvc.perform(delete("/v1/studies/{studyUuid}/root-networks", studyEntity.getId()) + .contentType(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(List.of(UUID.randomUUID()))) + .header("userId", USER_ID)) + .andExpect(status().isNotFound()); + + assertEquals(2, rootNetworkService.getStudyRootNetworks(studyEntity.getId()).size()); + } + @Test void testUpdateRootNetworkCase() throws Exception { final UUID studyUuid = UUID.randomUUID();