Skip to content

Commit

Permalink
Restore creation and application in one request
Browse files Browse the repository at this point in the history
Signed-off-by: Slimane AMAR <[email protected]>
  • Loading branch information
Slimane AMAR committed Jan 22, 2025
1 parent d3c2acc commit 9c11b44
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 398 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.tuple.Pair;
import org.gridsuite.modification.NetworkModificationException;
import org.gridsuite.modification.dto.ModificationInfos;
import org.gridsuite.modification.server.dto.*;
Expand Down Expand Up @@ -71,12 +72,41 @@ public ResponseEntity<Integer> getNetworkModificationsCount(@Parameter(descripti
@PostMapping(value = "/groups")
@Operation(summary = "Create a modification group based on another group")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The group and its modifications have been duplicated")})
public ResponseEntity<Void> createModificationGroup(@RequestParam("groupUuid") UUID groupUuid,
@RequestParam("duplicateFrom") UUID sourceGroupUuid) {
networkModificationService.createModificationGroup(sourceGroupUuid, groupUuid);
public ResponseEntity<Void> duplicateGroup(@RequestParam("groupUuid") UUID groupUuid,
@RequestParam("duplicateFrom") UUID sourceGroupUuid) {
networkModificationService.duplicateGroup(sourceGroupUuid, groupUuid);
return ResponseEntity.ok().build();
}

@PutMapping(value = "/groups/{groupUuid}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "For a list of network modifications passed in body, Move them before another one or at the end of the list, or Duplicate them at the end of the list")
@ApiResponse(responseCode = "200", description = "The modification list of the group has been updated.")
public ResponseEntity<List<Optional<NetworkModificationResult>>> handleNetworkModifications(@Parameter(description = "updated group UUID, where modifications are pasted") @PathVariable("groupUuid") UUID targetGroupUuid,
@Parameter(description = "kind of modification", required = true) @RequestParam(value = "action") GroupModificationAction action,
@Parameter(description = "the modification Uuid to move before (MOVE option, empty means moving at the end)") @RequestParam(value = "before", required = false) UUID beforeModificationUuid,
@Parameter(description = "origin group UUID, where modifications are copied or cut") @RequestParam(value = "originGroupUuid", required = false) UUID originGroupUuid,
@Parameter(description = "destination node can be built (default is true)") @RequestParam(value = "build", required = false, defaultValue = "true") Boolean build,
@RequestBody Pair<List<UUID>, List<ModificationApplicationContext>> modificationContextInfos) {
return switch (action) {
case COPY ->
ResponseEntity.ok().body(networkModificationService.duplicateModifications(targetGroupUuid, modificationContextInfos.getLeft(), modificationContextInfos.getRight()));
case INSERT ->
ResponseEntity.ok().body(networkModificationService.insertCompositeModifications(targetGroupUuid, modificationContextInfos.getLeft(), modificationContextInfos.getRight()));
case MOVE -> {
UUID sourceGroupUuid = originGroupUuid == null ? targetGroupUuid : originGroupUuid;
boolean canBuildNode = build;
if (sourceGroupUuid.equals(targetGroupUuid)) {
canBuildNode = false;
}
yield ResponseEntity.ok().body(networkModificationService.moveModifications(targetGroupUuid, sourceGroupUuid, beforeModificationUuid, modificationContextInfos.getLeft(), modificationContextInfos.getRight(), canBuildNode));
}
};
}

/**
* TODO : Remove this endpoint after the final integration of root networks (used only for move and tests)
* Need to use the new endpoint with modificationContextInfos DTO (see above)
*/
@PutMapping(value = "/groups/{groupUuid}", params = {"networkUuid", "reportUuid", "reporterId"}, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "For a list of network modifications passed in body, Move them before another one or at the end of the list, or Duplicate them at the end of the list")
@ApiResponse(responseCode = "200", description = "The modification list of the group has been updated.")
Expand Down Expand Up @@ -123,72 +153,36 @@ public ResponseEntity<List<UUID>> getModificationGroups() {
return ResponseEntity.ok().body(networkModificationService.getModificationGroups());
}

@PostMapping(value = "/network-modifications", params = {"networkUuid", "reportUuid", "reporterId"}, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PostMapping(value = "/network-modifications", params = "groupUuid", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Create a network modification")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "The network modification was created"),
@ApiResponse(responseCode = "404", description = "The network or equipment was not found")})
public ResponseEntity<Optional<NetworkModificationResult>> createNetworkModification(
@Parameter(description = "Network UUID") @RequestParam("networkUuid") UUID networkUuid,
@Parameter(description = "Variant ID") @RequestParam(name = "variantId", required = false) String variantId,
@Parameter(description = "Group UUID") @RequestParam(name = "groupUuid", required = false) UUID groupUuid,
@Parameter(description = "Report UUID") @RequestParam("reportUuid") UUID reportUuid,
@Parameter(description = "Reporter ID") @RequestParam("reporterId") String reporterId,
@RequestBody ModificationInfos modificationInfos) {
modificationInfos.check();
return ResponseEntity.ok().body(networkModificationService.createNetworkModification(networkUuid, variantId, groupUuid, new ReportInfos(reportUuid, UUID.fromString(reporterId)), modificationInfos));
public ResponseEntity<List<Optional<NetworkModificationResult>>> createNetworkModification(
@Parameter(description = "Group UUID") @RequestParam(name = "groupUuid") UUID groupUuid,
@RequestBody Pair<ModificationInfos, List<ModificationApplicationContext>> modificationContextInfos) {
modificationContextInfos.getLeft().check();
return ResponseEntity.ok().body(networkModificationService.createNetworkModification(groupUuid, modificationContextInfos.getLeft(), modificationContextInfos.getRight()));
}

/**
* Temporary endpoint linked to root network implementation
* This endpoint creates a modification without applying it, and returning its UUID in order to apply it later
* TODO : Remove this endpoint after the final integration of root networks (all tests need to migrate before)
* Need to use tne new endpoint with modificationContextInfos DTO (see above)
*/
@PostMapping(value = "/network-modifications", params = "groupUuid", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PostMapping(value = "/network-modifications", params = {"networkUuid", "reportUuid", "reporterId"}, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Create a network modification")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "The network modification was created"),
@ApiResponse(responseCode = "404", description = "The network or equipment was not found")})
public ResponseEntity<Optional<UUID>> createNetworkModificationWithoutApplying(
@Parameter(description = "Group UUID") @RequestParam(name = "groupUuid") UUID groupUuid,
public ResponseEntity<Optional<NetworkModificationResult>> createNetworkModification(
@Parameter(description = "Network UUID") @RequestParam("networkUuid") UUID networkUuid,
@Parameter(description = "Variant ID") @RequestParam(name = "variantId", required = false) String variantId,
@Parameter(description = "Group UUID") @RequestParam(name = "groupUuid", required = false) UUID groupUuid,
@Parameter(description = "Report UUID") @RequestParam("reportUuid") UUID reportUuid,
@Parameter(description = "Reporter ID") @RequestParam("reporterId") String reporterId,
@RequestBody ModificationInfos modificationInfos) {
modificationInfos.check();
return ResponseEntity.ok().body(networkModificationService.createNetworkModification(groupUuid, modificationInfos));
}

/**
* Temporary endpoint linked to root network implementation
* This endpoint creates a modification without applying it, and returning its UUID in order to apply it later
*/
@PutMapping(value = "/groups/{groupUuid}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "For a list of network modifications passed in body, Move them before another one or at the end of the list, or Duplicate them at the end of the list")
@ApiResponse(responseCode = "200", description = "The modification list of the group has been updated.")
public ResponseEntity<List<UUID>> handleNetworkModificationsWithoutApplying(@Parameter(description = "updated group UUID, where modifications are pasted") @PathVariable("groupUuid") UUID targetGroupUuid,
@Parameter(description = "kind of modification", required = true) @RequestParam(value = "action") GroupModificationAction action,
@Parameter(description = "the modification Uuid to move before (MOVE option, empty means moving at the end)") @RequestParam(value = "before", required = false) UUID beforeModificationUuid,
@Parameter(description = "origin group UUID, where modifications are copied or cut") @RequestParam(value = "originGroupUuid", required = false) UUID originGroupUuid,
@RequestBody List<UUID> modificationsUuidList) {
return switch (action) {
case COPY ->
ResponseEntity.ok().body(networkModificationService.duplicateModifications(targetGroupUuid, modificationsUuidList));
case INSERT ->
ResponseEntity.ok().body(networkModificationService.insertCompositeModifications(targetGroupUuid, modificationsUuidList));
case MOVE -> {
UUID sourceGroupUuid = originGroupUuid == null ? targetGroupUuid : originGroupUuid;
yield ResponseEntity.ok().body(networkModificationService.moveModifications(targetGroupUuid, sourceGroupUuid, beforeModificationUuid, modificationsUuidList));
}
};
}

/**
* Temporary endpoint linked to root network implementation
* This endpoint applied a list of modifications to multiple network variants, then return ordered impacts on those networks variants
*/
@PostMapping(value = "/network-modifications/apply", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Apply a list of modifications to a list of network contexts")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The network modification was updated")})
public ResponseEntity<List<Optional<NetworkModificationResult>>> applyNetworkModification(
@RequestBody MultipleNetworkModificationsInfos multipleNetworkModificationsInfos) {
return ResponseEntity.ok().body(networkModificationService.applyNetworkModifications(multipleNetworkModificationsInfos));
return ResponseEntity.ok().body(networkModificationService.createNetworkModification(networkUuid, variantId, groupUuid, new ReportInfos(reportUuid, UUID.fromString(reporterId)), modificationInfos));
}

@PutMapping(value = "/network-modifications/{uuid}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

import java.util.UUID;

public record NetworkModificationContextInfos(UUID networkUuid, String variantId, UUID reportUuid, UUID nodeUuid) { }
public record ModificationApplicationContext(UUID networkUuid, String variantId, UUID reportUuid, UUID nodeUuid) { }

This file was deleted.

Loading

0 comments on commit 9c11b44

Please sign in to comment.