Skip to content

Commit

Permalink
fix: tests after network modification changes
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 Jan 8, 2025
1 parent 9536b46 commit 5014584
Show file tree
Hide file tree
Showing 23 changed files with 467 additions and 215 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/gridsuite/study/server/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ public ResponseEntity<Void> restoreNodes(@Parameter(description = "study uuid")
@ApiResponse(responseCode = "200", description = "network modification tree"),
@ApiResponse(responseCode = "404", description = "The study or the node not found")})
public ResponseEntity<RootNode> getNetworkModificationTree(@Parameter(description = "study uuid") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "root network uuid") @RequestParam("rootNetworkUuid") UUID rootNetworkUuid) {
@Parameter(description = "root network uuid") @RequestParam(value = "rootNetworkUuid", required = false) UUID rootNetworkUuid) {
RootNode rootNode = networkModificationTreeService.getStudyTree(studyUuid, rootNetworkUuid);
return rootNode != null ?
ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(rootNode)
Expand All @@ -1320,7 +1320,7 @@ public ResponseEntity<RootNode> getNetworkModificationTree(@Parameter(descriptio
@ApiResponse(responseCode = "404", description = "The study or the parent node not found")})
public ResponseEntity<NetworkModificationNode> getNetworkModificationSubtree(@Parameter(description = "study uuid") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "parent node uuid") @RequestParam(value = "parentNodeUuid") UUID parentNodeUuid,
@Parameter(description = "root network uuid") @RequestParam(value = "rootNetworkUuid") UUID rootNetworkUuid) {
@Parameter(description = "root network uuid") @RequestParam(value = "rootNetworkUuid", required = false) UUID rootNetworkUuid) {
NetworkModificationNode parentNode = (NetworkModificationNode) networkModificationTreeService.getStudySubtree(studyUuid, parentNodeUuid, rootNetworkUuid);
return parentNode != null ?
ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(parentNode)
Expand Down Expand Up @@ -1359,7 +1359,7 @@ public ResponseEntity<Void> updateNodesColumnPositions(@RequestBody List<Network
@ApiResponse(responseCode = "404", description = "The study or the node not found")})
public ResponseEntity<AbstractNode> getNode(@Parameter(description = "study uuid") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "node uuid") @PathVariable("id") UUID nodeId,
@Parameter(description = "root network uuid") @RequestParam("rootNetworkUuid") UUID rootNetworkUuid) {
@Parameter(description = "root network uuid") @RequestParam(value = "rootNetworkUuid", required = false) UUID rootNetworkUuid) {
AbstractNode node = networkModificationTreeService.getNode(nodeId, rootNetworkUuid);
return node != null ?
ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(node)
Expand Down
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}/root-networks/{rootNetworkUuid}/equipments/indexation")
@DeleteMapping(value = "/studies/{studyUuid}/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 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)));
public ResponseEntity<String> deleteStudyIndexedEquipmentsAndTombstoned(@PathVariable("studyUuid") UUID studyUuid) {
return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(Long.toString(supervisionService.deleteStudyIndexedEquipmentsAndTombstoned(studyUuid)));
}

@GetMapping(value = "/orphan_indexed_network_uuids")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import org.gridsuite.study.server.networkmodificationtree.dto.*;
import org.gridsuite.study.server.networkmodificationtree.entities.NetworkModificationNodeInfoEntity;
import org.gridsuite.study.server.networkmodificationtree.entities.RootNetworkNodeInfoEntity;
import org.gridsuite.study.server.repository.networkmodificationtree.NetworkModificationNodeInfoRepository;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public Consumer<Message<String>> consumeCaseImportFailed() {
UUID studyUuid = receiver.getStudyUuid();
String userId = receiver.getUserId();

switch(receiver.getCaseImportAction()) {
switch (receiver.getCaseImportAction()) {
case STUDY_CREATION -> {
studyService.deleteStudyIfNotCreationInProgress(studyUuid, userId);
notificationService.emitStudyCreationError(studyUuid, userId, errorMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

import static org.gridsuite.study.server.StudyConstants.*;
Expand Down Expand Up @@ -71,14 +72,11 @@ public void persistNetwork(UUID caseUuid, UUID studyUuid, UUID rootNetworkUuid,

UriComponentsBuilder builder = UriComponentsBuilder.fromPath(DELIMITER + NETWORK_CONVERSION_API_VERSION + "/networks")
.queryParam(CASE_UUID, caseUuid)
.queryParamIfPresent(QUERY_PARAM_VARIANT_ID, Optional.ofNullable(variantId))
.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
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,9 @@ private AbstractNode getSimpleNode(UUID nodeId) {
public AbstractNode getNode(UUID nodeId, UUID rootNetworkUuid) {
AbstractNode node = getSimpleNode(nodeId);
nodesRepository.findAllByParentNodeIdNode(node.getId()).stream().map(NodeEntity::getIdNode).forEach(node.getChildrenIds()::add);
completeNodeInfos(List.of(node), rootNetworkUuid);
if (rootNetworkUuid != null) {
completeNodeInfos(List.of(node), rootNetworkUuid);
}
return node;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ public List<CompletableFuture<Void>> getDeleteRootNetworkNodeInfosFutures(List<R
);
}

@Transactional
public NetworkModificationContextInfos getNetworkModificationContextInfos(UUID rootNetworkUuid, UUID nodeUuid, UUID networkUuid) {
RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = getRootNetworkNodeInfo(nodeUuid, rootNetworkUuid).orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND));
String variantId = rootNetworkNodeInfoEntity.getVariantId();
Expand Down
21 changes: 9 additions & 12 deletions src/main/java/org/gridsuite/study/server/service/StudyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -789,9 +789,9 @@ public void assertNoBuildNoComputationForRootNetworkNode(UUID nodeUuid, UUID roo
}

public void assertNoBuildNoComputationForNode(UUID studyUuid, UUID nodeUuid) {
rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetwork -> {
rootNetworkNodeInfoService.assertComputationNotRunning(nodeUuid, rootNetwork.getId());
});
rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetwork ->
rootNetworkNodeInfoService.assertComputationNotRunning(nodeUuid, rootNetwork.getId())
);
rootNetworkNodeInfoService.assertNoRootNetworkNodeIsBuilding(studyUuid);
}

Expand Down Expand Up @@ -1482,9 +1482,9 @@ public void moveStudyNode(UUID studyUuid, UUID nodeToMoveUuid, UUID referenceNod
updateStatuses(studyUuid, nodeToMoveUuid, false, true, true);
oldChildren.forEach(child -> updateStatuses(studyUuid, child.getIdNode(), false, true, true));
} else {
rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> {
invalidateBuild(studyUuid, nodeToMoveUuid, rootNetworkEntity.getId(), false, true, true);
});
rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity ->
invalidateBuild(studyUuid, nodeToMoveUuid, rootNetworkEntity.getId(), false, true, true)
);
}
notificationService.emitElementUpdated(studyUuid, userId);
}
Expand Down Expand Up @@ -1711,9 +1711,9 @@ public void stashNode(UUID studyUuid, UUID nodeId, boolean stashChildren, String
AtomicReference<Long> startTime = new AtomicReference<>(null);
startTime.set(System.nanoTime());
boolean invalidateChildrenBuild = stashChildren || networkModificationTreeService.hasModifications(nodeId, false);
rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> {
invalidateBuild(studyUuid, nodeId, rootNetworkEntity.getId(), false, !invalidateChildrenBuild, true);
});
rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity ->
invalidateBuild(studyUuid, nodeId, rootNetworkEntity.getId(), false, !invalidateChildrenBuild, true)
);
networkModificationTreeService.doStashNode(nodeId, stashChildren);

if (startTime.get() != null) {
Expand Down Expand Up @@ -1798,18 +1798,15 @@ 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));
//TODO : should take rootnetworkuuid as param
updateStatuses(studyUuid, targetNodeUuid, buildTargetNode, true, true);
}
if (moveBetweenNodes) {
// invalidate the whole subtree including the source node
networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, originNodeUuid, rootNetworkUuid, modificationResult));
//TODO : should take rootnetworkuuid as param
updateStatuses(studyUuid, originNodeUuid, false, true, true);
}
});
} finally {
//TODO : should take rootnetworkuuid as param
notificationService.emitEndModificationEquipmentNotification(studyUuid, targetNodeUuid, childrenUuids);
if (moveBetweenNodes) {
notificationService.emitEndModificationEquipmentNotification(studyUuid, originNodeUuid, originNodeChildrenUuids);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import org.gridsuite.study.server.StudyException;
import org.gridsuite.study.server.elasticsearch.EquipmentInfosService;
import org.gridsuite.study.server.networkmodificationtree.dto.RootNode;
import org.gridsuite.study.server.networkmodificationtree.entities.RootNetworkNodeInfoEntity;
import org.gridsuite.study.server.repository.rootnetwork.RootNetworkNodeInfoRepository;
import org.gridsuite.study.server.service.dynamicsimulation.DynamicSimulationService;
Expand Down Expand Up @@ -135,17 +134,22 @@ public long getIndexedTombstonedEquipmentsCount() {
}

@Transactional
public Long deleteStudyIndexedEquipmentsAndTombstoned(UUID studyUuid, UUID rootNetworkUuid) {
public Long deleteStudyIndexedEquipmentsAndTombstoned(UUID studyUuid) {
AtomicReference<Long> startTime = new AtomicReference<>();
startTime.set(System.nanoTime());

UUID networkUUID = rootNetworkService.getNetworkUuid(rootNetworkUuid);
Long nbIndexesToDelete = getStudyIndexedEquipmentsCount(networkUUID) + getStudyIndexedTombstonedEquipmentsCount(networkUUID);
equipmentInfosService.deleteAllByNetworkUuid(networkUUID);
AtomicReference<Long> nbIndexesToDelete = new AtomicReference<>(0L);

rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> {
UUID networkUUID = rootNetworkService.getNetworkUuid(rootNetworkEntity.getId());
nbIndexesToDelete.updateAndGet(v -> v + getStudyIndexedEquipmentsCount(networkUUID) + getStudyIndexedTombstonedEquipmentsCount(networkUUID));
equipmentInfosService.deleteAllByNetworkUuid(networkUUID);
});

studyService.updateStudyIndexationStatus(studyUuid, StudyIndexationStatus.NOT_INDEXED);

LOGGER.trace("Indexed equipments deletion for study \"{}\": {} seconds", studyUuid, TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTime.get()));
return nbIndexesToDelete;
return nbIndexesToDelete.get();
}

private Integer deleteLoadflowResults() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/gridsuite/study/server/LoadFlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ void testDeleteLoadFlowResults(final MockWebServer server) throws Exception {
void testResetUuidResultWhenLFFailed() throws Exception {
UUID resultUuid = UUID.randomUUID();
StudyEntity studyEntity = insertDummyStudy(UUID.randomUUID(), UUID.randomUUID(), LOADFLOW_PARAMETERS_UUID);
RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId());
RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId(), null);
NetworkModificationNode modificationNode = createNetworkModificationNode(studyEntity.getId(), rootNode.getId(), UUID.randomUUID(), VARIANT_ID, "node 1");
UUID rootNetworkUuid = studyEntity.getFirstRootNetwork().getId();
String resultUuidJson = objectMapper.writeValueAsString(new NodeReceiver(modificationNode.getId(), rootNetworkUuid));
Expand Down
Loading

0 comments on commit 5014584

Please sign in to comment.