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"))