Skip to content

Commit

Permalink
feat: migrate modifications endpoints to root network uuid usage
Browse files Browse the repository at this point in the history
Signed-off-by: LE SAULNIER Kevin <[email protected]>
  • Loading branch information
LE SAULNIER Kevin committed Dec 16, 2024
1 parent 17cd75b commit bd3f5c0
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 206 deletions.
49 changes: 22 additions & 27 deletions src/main/java/org/gridsuite/study/server/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,9 @@ public ResponseEntity<Void> 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();
}
Expand All @@ -572,14 +572,15 @@ public ResponseEntity<Void> 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<UUID> 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:
Expand Down Expand Up @@ -1131,10 +1132,10 @@ public ResponseEntity<String> 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<Void> 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();
}
Expand All @@ -1147,9 +1148,8 @@ public ResponseEntity<Void> 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();
}

Expand All @@ -1160,9 +1160,8 @@ public ResponseEntity<Void> deleteNetworkModifications(@Parameter(description =
@Parameter(description = "Node UUID") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "Network modification UUIDs") @RequestParam(name = "uuids", required = false) List<UUID> 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();
}
Expand All @@ -1173,10 +1172,10 @@ public ResponseEntity<Void> deleteNetworkModifications(@Parameter(description =
public ResponseEntity<Void> 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<UUID> 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 {
Expand All @@ -1191,10 +1190,10 @@ public ResponseEntity<Void> stashNetworkModifications(@Parameter(description = "
public ResponseEntity<Void> 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<UUID> 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();
}
Expand Down Expand Up @@ -1247,8 +1246,7 @@ public ResponseEntity<Void> deleteNode(@Parameter(description = "study uuid") @P
@Parameter(description = "ids of children to remove") @RequestParam("ids") List<UUID> 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();
}

Expand Down Expand Up @@ -1365,7 +1363,7 @@ public ResponseEntity<Void> 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();
}
Expand Down Expand Up @@ -1607,8 +1605,7 @@ public ResponseEntity<Void> 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();
}
Expand All @@ -1622,8 +1619,7 @@ public ResponseEntity<Void> 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();
}
Expand All @@ -1637,8 +1633,7 @@ public ResponseEntity<Void> deleteDynamicSimulationEvents(@Parameter(description
@Parameter(description = "Node UUID") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "Dynamic simulation event UUIDs") @RequestParam("eventUuids") List<UUID> 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();
}
Expand Down Expand Up @@ -1748,7 +1743,7 @@ public ResponseEntity<Void> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ public interface RootNetworkRepository extends JpaRepository<RootNetworkEntity,
@EntityGraph(attributePaths = {"rootNetworkNodeInfos"}, type = EntityGraph.EntityGraphType.LOAD)
Optional<RootNetworkEntity> findWithRootNetworkNodeInfosById(UUID rootNetworkUuid);

boolean existsByIdAndStudyId(UUID studyUuid, UUID id);
boolean existsByIdAndStudyId(UUID rootNetworkUuid, UUID studyUuid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,14 @@ public Optional<NetworkModificationResult> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,19 @@ public List<UUID> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit bd3f5c0

Please sign in to comment.