Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate network modifications endpoints to add rootNetworkUuid in path #657

Open
wants to merge 11 commits into
base: root-network-various-endpoints
Choose a base branch
from
123 changes: 61 additions & 62 deletions src/main/java/org/gridsuite/study/server/StudyController.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public ResponseEntity<String> getIndexedTombstonedEquipmentsCount() {
return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(Long.toString(supervisionService.getIndexedTombstonedEquipmentsCount()));
}

@DeleteMapping(value = "/studies/{studyUuid}/equipments/indexation")
@DeleteMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/equipments/indexation")
@Operation(summary = "delete indexed equipments and tombstoned equipments for the given study")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "all indexed equipments and tombstoned equipments for the given study have been deleted")})
public ResponseEntity<String> deleteStudyIndexedEquipmentsAndTombstoned(@PathVariable("studyUuid") UUID studyUuid) {
return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(Long.toString(supervisionService.deleteStudyIndexedEquipmentsAndTombstoned(studyUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid))));
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "all indexed equipments and tombstoned equipments for the given study for the given root network have been deleted")})
public ResponseEntity<String> deleteStudyIndexedEquipmentsAndTombstoned(@PathVariable("studyUuid") UUID studyUuid, @PathVariable("rootNetworkUuid") UUID rootNetworkUuid) {
return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(Long.toString(supervisionService.deleteStudyIndexedEquipmentsAndTombstoned(studyUuid, rootNetworkUuid)));
}

@GetMapping(value = "/orphan_indexed_network_uuids")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.gridsuite.study.server.dto;

import java.util.UUID;

public record RootNetworkMinimalInfos(UUID rootNetworkUuid, boolean isCreating) { }
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.study.server.dto.modification;

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.study.server.dto.modification;

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 @@ -23,9 +23,7 @@ public NetworkModificationNodeInfoRepositoryProxy(NetworkModificationNodeInfoRep
@Override
public NetworkModificationNode toDto(NetworkModificationNodeInfoEntity node) {
@SuppressWarnings("unused")
RootNetworkNodeInfoEntity rootNetworkNodeStatusEntity = node.getFirstRootNetworkNodeInfosEntity();
NetworkModificationNode networkModificationNode = NetworkModificationNode.builder().modificationGroupUuid(node.getModificationGroupUuid()).build();
networkModificationNode.completeDtoFromRootNetworkNodeInfo(rootNetworkNodeStatusEntity);
return completeNodeInfo(node, networkModificationNode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class NotificationService {

public static final String HEADER_ERROR = "error";
public static final String HEADER_NODE = "node";
public static final String HEADER_ROOT_NETWORK = "rootNetwork";
public static final String HEADER_NODES = "nodes";
public static final String HEADER_STUDY_UUID = "studyUuid";
public static final String HEADER_UPDATE_TYPE = "updateType";
Expand Down Expand Up @@ -116,6 +117,9 @@ public class NotificationService {
public static final String MESSAGE_LOG = "Sending message : {}";
public static final String DEFAULT_ERROR_MESSAGE = "Unknown error";

public static final String ROOT_NETWORKS_UPDATED = "rootNetworksUpdated";
public static final String ROOT_NETWORKS_UPDATE_FAILED = "rootNetworksUpdateFailed";

public static final String STUDY_ALERT = "STUDY_ALERT";

private static final String CATEGORY_BROKER_OUTPUT = NotificationService.class.getName() + ".output-broker-messages";
Expand Down Expand Up @@ -161,10 +165,11 @@ public void emitStudyNetworkRecreationDone(UUID studyUuid, String userId) {
}

@PostCompletion
public void emitStudyChanged(UUID studyUuid, UUID nodeUuid, String updateType) {
public void emitStudyChanged(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String updateType) {
sendUpdateMessage(MessageBuilder.withPayload("")
.setHeader(HEADER_STUDY_UUID, studyUuid)
.setHeader(HEADER_NODE, nodeUuid)
.setHeader(HEADER_ROOT_NETWORK, rootNetworkUuid)
.setHeader(HEADER_UPDATE_TYPE, updateType)
.build());
}
Expand All @@ -191,31 +196,34 @@ public void emitStudyCreationError(UUID studyUuid, String userId, String errorMe
}

@PostCompletion
public void emitStudyError(UUID studyUuid, UUID nodeUuid, String updateType, String errorMessage, String userId) {
public void emitStudyError(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String updateType, String errorMessage, String userId) {
sendUpdateMessage(MessageBuilder.withPayload("")
.setHeader(HEADER_STUDY_UUID, studyUuid)
.setHeader(HEADER_NODE, nodeUuid)
.setHeader(HEADER_ROOT_NETWORK, rootNetworkUuid)
.setHeader(HEADER_UPDATE_TYPE, updateType)
.setHeader(HEADER_ERROR, errorMessage)
.setHeader(HEADER_USER_ID, userId)
.build());
}

@PostCompletion
public void emitStudyChanged(UUID studyUuid, UUID nodeUuid, String updateType, Set<String> substationsIds) {
public void emitStudyChanged(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String updateType, Set<String> substationsIds) {
sendUpdateMessage(MessageBuilder.withPayload("")
.setHeader(HEADER_STUDY_UUID, studyUuid)
.setHeader(HEADER_NODE, nodeUuid)
.setHeader(HEADER_ROOT_NETWORK, rootNetworkUuid)
.setHeader(HEADER_UPDATE_TYPE, updateType)
.setHeader(HEADER_UPDATE_TYPE_SUBSTATIONS_IDS, substationsIds)
.build());
}

@PostCompletion
public void emitStudyChanged(UUID studyUuid, UUID nodeUuid, String updateType, NetworkImpactsInfos networkImpactsInfos) {
public void emitStudyChanged(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String updateType, NetworkImpactsInfos networkImpactsInfos) {
try {
sendUpdateMessage(MessageBuilder.withPayload(objectMapper.writeValueAsString(networkImpactsInfos)).setHeader(HEADER_STUDY_UUID, studyUuid)
.setHeader(HEADER_NODE, nodeUuid)
.setHeader(HEADER_ROOT_NETWORK, rootNetworkUuid)
.setHeader(HEADER_UPDATE_TYPE, updateType)
.build());
} catch (JsonProcessingException e) {
Expand Down Expand Up @@ -280,10 +288,11 @@ public void emitNodesChanged(UUID studyUuid, Collection<UUID> nodes) {
}

@PostCompletion
public void emitNodeBuildFailed(UUID studyUuid, UUID nodeUuid, String errorMessage) {
public void emitNodeBuildFailed(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String errorMessage) {
sendUpdateMessage(MessageBuilder.withPayload("")
.setHeader(HEADER_STUDY_UUID, studyUuid)
.setHeader(HEADER_NODE, nodeUuid)
.setHeader(HEADER_ROOT_NETWORK, rootNetworkUuid)
.setHeader(HEADER_UPDATE_TYPE, UPDATE_TYPE_BUILD_FAILED)
.setHeader(HEADER_ERROR, errorMessage)
.build());
Expand Down Expand Up @@ -312,11 +321,12 @@ public void emitSubtreeInserted(UUID studyUuid, UUID parentNodeSubtreeInserted,
}

@PostCompletion
public void emitNodeBuildStatusUpdated(UUID studyUuid, Collection<UUID> nodes) {
public void emitNodeBuildStatusUpdated(UUID studyUuid, Collection<UUID> nodes, UUID rootNetworkUuid) {
sendUpdateMessage(MessageBuilder.withPayload("")
.setHeader(HEADER_STUDY_UUID, studyUuid)
.setHeader(HEADER_UPDATE_TYPE, NODE_BUILD_STATUS_UPDATED)
.setHeader(HEADER_NODES, nodes)
.setHeader(HEADER_ROOT_NETWORK, rootNetworkUuid)
.build()
);
}
Expand Down Expand Up @@ -406,17 +416,35 @@ public void emitElementUpdated(UUID elementUuid, String modifiedBy) {
}

@PostCompletion
public void emitStudyAlert(UUID studyUuid, UUID nodeUuid, String userId, StudyAlert studyAlert) {
public void emitStudyAlert(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String userId, StudyAlert studyAlert) {
try {
sendUpdateMessage(MessageBuilder.withPayload(objectMapper.writeValueAsString(studyAlert))
.setHeader(HEADER_USER_ID, userId)
.setHeader(HEADER_STUDY_UUID, studyUuid)
.setHeader(HEADER_NODE, nodeUuid)
.setHeader(HEADER_ROOT_NETWORK, rootNetworkUuid)
.setHeader(HEADER_UPDATE_TYPE, STUDY_ALERT)
.build()
);
} catch (JsonProcessingException e) {
LOGGER.error("Unable to notify on study alert", e);
}
}

@PostCompletion
public void emitRootNetworksUpdated(UUID studyUuid) {
sendUpdateMessage(MessageBuilder.withPayload("")
.setHeader(HEADER_STUDY_UUID, studyUuid)
.setHeader(HEADER_UPDATE_TYPE, ROOT_NETWORKS_UPDATED)
.build());
}

@PostCompletion
public void emitRootNetworksUpdateFailed(UUID studyUuid, String errorMessage) {
sendUpdateMessage(MessageBuilder.withPayload("")
.setHeader(HEADER_STUDY_UUID, studyUuid)
.setHeader(HEADER_UPDATE_TYPE, ROOT_NETWORKS_UPDATE_FAILED)
.setHeader(HEADER_ERROR, errorMessage)
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

import org.springframework.data.jpa.repository.JpaRepository;

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

public interface RootNetworkCreationRequestRepository extends JpaRepository<RootNetworkCreationRequestEntity, UUID> {
List<RootNetworkCreationRequestEntity> findAllByStudyUuid(UUID studyUuid);
}
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 @@ -113,7 +113,7 @@ public Consumer<Message<NetworkModificationResult>> consumeBuildResult() {
NodeBuildStatus.from(networkModificationResult.getLastGroupApplicationStatus(), networkModificationResult.getApplicationStatus()));

UUID studyUuid = networkModificationTreeService.getStudyUuidForNodeId(receiverObj.getNodeUuid());
notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), NotificationService.UPDATE_TYPE_BUILD_COMPLETED, networkModificationResult.getImpactedSubstationsIds());
notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), receiverObj.getRootNetworkUuid(), NotificationService.UPDATE_TYPE_BUILD_COMPLETED, networkModificationResult.getImpactedSubstationsIds());
} catch (Exception e) {
LOGGER.error(e.toString());
}
Expand All @@ -137,7 +137,7 @@ public Consumer<Message<String>> consumeBuildStopped() {

// send notification
UUID studyUuid = networkModificationTreeService.getStudyUuidForNodeId(receiverObj.getNodeUuid());
notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), NotificationService.UPDATE_TYPE_BUILD_CANCELLED);
notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), receiverObj.getRootNetworkUuid(), NotificationService.UPDATE_TYPE_BUILD_CANCELLED);
} catch (JsonProcessingException e) {
LOGGER.error(e.toString());
}
Expand All @@ -161,7 +161,7 @@ public Consumer<Message<String>> consumeBuildFailed() {

// send notification
UUID studyUuid = networkModificationTreeService.getStudyUuidForNodeId(receiverObj.getNodeUuid());
notificationService.emitNodeBuildFailed(studyUuid, receiverObj.getNodeUuid(), message.getHeaders().get(HEADER_MESSAGE, String.class));
notificationService.emitNodeBuildFailed(studyUuid, receiverObj.getNodeUuid(), receiverObj.getRootNetworkUuid(), message.getHeaders().get(HEADER_MESSAGE, String.class));
} catch (JsonProcessingException e) {
LOGGER.error(e.toString());
}
Expand Down Expand Up @@ -382,8 +382,13 @@ public Consumer<Message<String>> consumeCaseImportFailed() {
UUID studyUuid = receiver.getStudyUuid();
String userId = receiver.getUserId();

studyService.deleteStudyIfNotCreationInProgress(studyUuid, userId);
notificationService.emitStudyCreationError(studyUuid, userId, errorMessage);
switch(receiver.getCaseImportAction()) {
case STUDY_CREATION -> {
studyService.deleteStudyIfNotCreationInProgress(studyUuid, userId);
notificationService.emitStudyCreationError(studyUuid, userId, errorMessage);
}
case ROOT_NETWORK_CREATION, ROOT_NETWORK_MODIFICATION -> notificationService.emitRootNetworksUpdateFailed(studyUuid, errorMessage);
}
} catch (Exception e) {
LOGGER.error(e.toString(), e);
}
Expand Down Expand Up @@ -422,6 +427,7 @@ public void consumeCalculationFailed(Message<String> msg, ComputationType comput
notificationService.emitStudyError(
studyUuid,
receiverObj.getNodeUuid(),
receiverObj.getRootNetworkUuid(),
computationType.getUpdateFailedType(),
errorMessage,
userId);
Expand All @@ -442,7 +448,7 @@ public void consumeCalculationStopped(Message<String> msg, ComputationType compu
rootNetworkNodeInfoService.updateComputationResultUuid(receiverObj.getNodeUuid(), receiverObj.getRootNetworkUuid(), null, computationType);
UUID studyUuid = networkModificationTreeService.getStudyUuidForNodeId(receiverObj.getNodeUuid());
// send notification for stopped computation
notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), computationType.getUpdateStatusType());
notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), receiverObj.getRootNetworkUuid(), computationType.getUpdateStatusType());

LOGGER.info("{} stopped for node '{}'", computationType.getLabel(), receiverObj.getNodeUuid());
} catch (JsonProcessingException e) {
Expand All @@ -464,6 +470,7 @@ public void consumeCalculationCancelFailed(Message<String> msg, ComputationType
notificationService.emitStudyError(
studyUuid,
receiverObj.getNodeUuid(),
receiverObj.getRootNetworkUuid(),
updateType,
errorMessage,
userId
Expand All @@ -489,8 +496,8 @@ public void consumeCalculationResult(Message<String> msg, ComputationType comput

UUID studyUuid = networkModificationTreeService.getStudyUuidForNodeId(receiverObj.getNodeUuid());
// send notifications
notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), computationType.getUpdateStatusType());
notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), computationType.getUpdateResultType());
notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), receiverObj.getRootNetworkUuid(), computationType.getUpdateStatusType());
notificationService.emitStudyChanged(studyUuid, receiverObj.getNodeUuid(), receiverObj.getRootNetworkUuid(), computationType.getUpdateResultType());
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,17 @@ public void persistNetwork(UUID caseUuid, UUID studyUuid, UUID rootNetworkUuid,
throw new UncheckedIOException(e);
}

String path = UriComponentsBuilder.fromPath(DELIMITER + NETWORK_CONVERSION_API_VERSION + "/networks")
.queryParam(CASE_UUID, caseUuid)
.queryParam(QUERY_PARAM_VARIANT_ID, variantId)
.queryParam(REPORT_UUID, importReportUuid)
.queryParam(QUERY_PARAM_RECEIVER, receiver)
.queryParam(CASE_FORMAT, caseFormat)
UriComponentsBuilder builder = UriComponentsBuilder.fromPath(DELIMITER + NETWORK_CONVERSION_API_VERSION + "/networks")
.queryParam(CASE_UUID, caseUuid)
.queryParam(REPORT_UUID, importReportUuid)
.queryParam(QUERY_PARAM_RECEIVER, receiver)
.queryParam(CASE_FORMAT, caseFormat);

if (variantId != null) {
builder.queryParam(QUERY_PARAM_VARIANT_ID, variantId);
}

String path = builder
.buildAndExpand()
.toUriString();

Expand Down
Loading
Loading