Skip to content

Commit

Permalink
feat: endpoints to create modifications without applying them + endpo…
Browse files Browse the repository at this point in the history
…int to apply modifications on multiple network contexts

Signed-off-by: LE SAULNIER Kevin <[email protected]>
  • Loading branch information
LE SAULNIER Kevin committed Dec 23, 2024
1 parent 82bc06a commit 2fe878d
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,34 @@ public ResponseEntity<Optional<NetworkModificationResult>> createNetworkModifica
return ResponseEntity.ok().body(networkModificationService.createNetworkModification(networkUuid, variantId, groupUuid, new ReportInfos(reportUuid, UUID.fromString(reporterId)), 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
*/
@PostMapping(value = "/network-modifications", 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", required = false) UUID groupUuid,
@RequestBody ModificationInfos modificationInfos) {
modificationInfos.check();
return ResponseEntity.ok().body(networkModificationService.createNetworkModification(groupUuid, modificationInfos));
}

/**
* 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));
}

@PutMapping(value = "/network-modifications/{uuid}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Update a network modification")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The network modification was updated")})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.modification.server.dto;

import java.util.List;
import java.util.UUID;

public record MultipleNetworkModificationsInfos(List<UUID> modificationsUuid, List<NetworkModificationContextInfos> networkModificationContextInfos) { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.modification.server.dto;

import java.util.UUID;

public record NetworkModificationContextInfos(UUID networkUuid, String variantId, UUID reportUuid, UUID nodeUuid) { }
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ public void deleteAll() {
// This method should be package-private and not used as API of the service as it uses ModificationEntity and
// we want to encapsulate the use of Entity related objects to this service.
// Nevertheless We have to keep it public for transactional annotation.
public void saveModifications(UUID groupUuid, List<? extends ModificationEntity> modifications) {
saveModificationsNonTransactional(groupUuid, modifications);
public List<? extends ModificationEntity> saveModifications(UUID groupUuid, List<? extends ModificationEntity> modifications) {
return saveModificationsNonTransactional(groupUuid, modifications);
}

@Transactional // To have all create in the same transaction (atomic)
// TODO Remove transaction when errors will no longer be sent to the front
public void saveModificationInfos(UUID groupUuid, List<? extends ModificationInfos> modifications) {
public List<? extends ModificationEntity> saveModificationInfos(UUID groupUuid, List<? extends ModificationInfos> modifications) {
List<ModificationEntity> entities = modifications.stream().map(ModificationEntity::fromDTO).toList();

saveModificationsNonTransactional(groupUuid, entities);
return saveModificationsNonTransactional(groupUuid, entities);
}

public UUID createNetworkCompositeModification(@NonNull List<UUID> modificationUuids) {
Expand All @@ -85,7 +85,7 @@ public UUID createNetworkCompositeModification(@NonNull List<UUID> modificationU
return modificationRepository.save(compositeEntity).getId();
}

private void saveModificationsNonTransactional(UUID groupUuid, List<? extends ModificationEntity> modifications) {
private List<? extends ModificationEntity> saveModificationsNonTransactional(UUID groupUuid, List<? extends ModificationEntity> modifications) {
int order = modificationRepository.countByGroupIdAndStashed(groupUuid, false);
var modificationGroupEntity = this.modificationGroupRepository
.findById(groupUuid)
Expand All @@ -95,7 +95,7 @@ private void saveModificationsNonTransactional(UUID groupUuid, List<? extends Mo
m.setModificationsOrder(order);
order++;
}
modificationRepository.saveAll(modifications);
return modificationRepository.saveAll(modifications);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,27 @@ public Optional<NetworkModificationResult> createNetworkModification(@NonNull UU
Optional.empty();
}

/**
* Temporary method linked to root network implementation
*/
public Optional<UUID> createNetworkModification(@NonNull UUID groupUuid, @NonNull ModificationInfos modificationInfos) {
return networkModificationRepository.saveModificationInfos(groupUuid, List.of(modificationInfos)).stream().map(ModificationEntity::getId).findFirst();
}

/**
* Temporary method linked to root network implementation
*/
public List<Optional<NetworkModificationResult>> applyNetworkModifications(MultipleNetworkModificationsInfos multipleNetworkModificationsInfos) {
List<ModificationInfos> modificationsToApply = networkModificationRepository.getModificationsInfos(multipleNetworkModificationsInfos.modificationsUuid());
return multipleNetworkModificationsInfos.networkModificationContextInfos().stream().map(networkModificationContextInfos ->
applyModifications(networkModificationContextInfos.networkUuid(),
networkModificationContextInfos.variantId(),
new ReportInfos(networkModificationContextInfos.reportUuid(),
networkModificationContextInfos.nodeUuid()),
modificationsToApply)
).toList();
}

public Network cloneNetworkVariant(UUID networkUuid,
String originVariantId,
String destinationVariantId,
Expand Down

0 comments on commit 2fe878d

Please sign in to comment.