Skip to content

Commit

Permalink
fix: modification duplication + report endpoint
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 3, 2025
1 parent 17f2c01 commit d5a1d36
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1102,15 +1102,17 @@ public ResponseEntity<List<Report>> getParentNodesReport(@Parameter(description
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getParentNodesReport(nodeUuid, rootNetworkUuid, nodeOnlyReport, reportType, severityLevels));
}

@GetMapping(value = "/studies/{studyUuid}/nodes/{nodeUuid}/report/{reportId}/logs", produces = MediaType.APPLICATION_JSON_VALUE)
@GetMapping(value = "/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/report/{reportId}/logs", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get node report logs")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The node report logs"), @ApiResponse(responseCode = "404", description = "The study/node is not found")})
public ResponseEntity<List<ReportLog>> getNodeReportLogs(@Parameter(description = "Study uuid") @PathVariable("studyUuid") UUID studyUuid,
@Parameter(description = "root network id") @PathVariable("rootNetworkUuid") UUID rootNetworkUuid,
@Parameter(description = "node id") @PathVariable("nodeUuid") UUID nodeUuid,
@Parameter(description = "reportId") @PathVariable("reportId") String reportId,
@Parameter(description = "the message filter") @RequestParam(name = "message", required = false) String messageFilter,
@Parameter(description = "Severity levels filter") @RequestParam(name = "severityLevels", required = false) Set<String> severityLevels) {
studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid);
rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkUuid);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getReportLogs(reportId, messageFilter, severityLevels));
}

Expand All @@ -1123,6 +1125,7 @@ public ResponseEntity<List<ReportLog>> getParentNodesReportLogs(@Parameter(descr
@Parameter(description = "the message filter") @RequestParam(name = "message", required = false) String messageFilter,
@Parameter(description = "Severity levels filter") @RequestParam(name = "severityLevels", required = false) Set<String> severityLevels) {
studyService.assertIsStudyAndNodeExist(studyUuid, nodeUuid);
rootNetworkService.assertIsRootNetworkInStudy(studyUuid, rootNetworkUuid);
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(studyService.getParentNodesReportLogs(nodeUuid, rootNetworkUuid, messageFilter, severityLevels));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,19 @@ public Optional<NetworkModificationResult> createModifications(List<UUID> modifi
}).getBody();
}

public List<UUID> handleNetworkModificationsWithoutApplying(List<UUID> modificationUuidList, NetworkModificationNodeInfoEntity networkModificationNodeInfoEntity, ModificationsActionType action) {
var path = UriComponentsBuilder.fromPath(GROUP_PATH)
.queryParam(QUERY_PARAM_ACTION, action.name());

HttpEntity<String> httpEntity = getModificationsUuidBody(modificationUuidList);
return restTemplate.exchange(
getNetworkModificationServerURI(false) + path.buildAndExpand(networkModificationNodeInfoEntity.getModificationGroupUuid()).toUriString(),
HttpMethod.PUT,
httpEntity,
new ParameterizedTypeReference<List<UUID>>() {
}).getBody();
}

public void createModifications(UUID sourceGroupUuid, UUID groupUuid) {
Objects.requireNonNull(groupUuid);
Objects.requireNonNull(sourceGroupUuid);
Expand Down
31 changes: 20 additions & 11 deletions src/main/java/org/gridsuite/study/server/service/StudyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1825,17 +1825,26 @@ public void createModifications(UUID studyUuid, UUID nodeUuid, List<UUID> modifi
try {
checkStudyContainsNode(studyUuid, nodeUuid);
NetworkModificationNodeInfoEntity networkModificationNodeInfoEntity = networkModificationTreeService.getNetworkModificationNodeInfoEntity(nodeUuid);
//TODO : not ok, creating multiple times the same modification for each root network
rootNetworkService.getStudyRootNetworks(studyUuid).forEach(rootNetworkEntity -> {
UUID rootNetworkUuid = rootNetworkEntity.getId();
RootNetworkNodeInfoEntity rootNetworkNodeInfoEntity = rootNetworkNodeInfoService.getRootNetworkNodeInfo(nodeUuid, rootNetworkUuid).orElseThrow(() -> new StudyException(ROOT_NETWORK_NOT_FOUND));
UUID networkUuid = rootNetworkService.getNetworkUuid(rootNetworkUuid);
Optional<NetworkModificationResult> networkModificationResult = networkModificationService.createModifications(modificationUuidList, networkUuid, networkModificationNodeInfoEntity, rootNetworkNodeInfoEntity, action);
// invalidate the whole subtree except the target node (we have built this node during the duplication)
networkModificationResult.ifPresent(modificationResult -> emitNetworkModificationImpacts(studyUuid, nodeUuid, rootNetworkUuid, modificationResult));
});
//TODO: NOT WORKING WELL, NOTIF HAS TO TARGET ROOT NETWORK UUID
updateStatuses(studyUuid, nodeUuid, true, true, true);
List<RootNetworkEntity> studyRootNetworkEntities = rootNetworkService.getStudyRootNetworks(studyUuid);
List<UUID> updatedModificationUuidList = networkModificationService.handleNetworkModificationsWithoutApplying(modificationUuidList, networkModificationNodeInfoEntity, action);

List<Optional<NetworkModificationResult>> networkModificationResults = networkModificationService.applyModifications(new MultipleNetworkModificationsInfos(
updatedModificationUuidList,
studyRootNetworkEntities.stream().map(rootNetworkEntity -> rootNetworkNodeInfoService.getNetworkModificationContextInfos(rootNetworkEntity.getId(), nodeUuid, rootNetworkEntity.getNetworkUuid())
).toList()));

if (networkModificationResults != null) {
int index = 0;
// for each NetworkModificationResult, send an impact notification - studyRootNetworkEntities are ordered in the same way as networkModificationResults
for (Optional<NetworkModificationResult> modificationResultOpt : networkModificationResults) {
if (modificationResultOpt.isPresent() && studyRootNetworkEntities.get(index) != null) {
emitNetworkModificationImpacts(studyUuid, nodeUuid, studyRootNetworkEntities.get(index).getId(), modificationResultOpt.get());
}
index++;
}
}
// invalidate all nodeUuid children
updateStatuses(studyUuid, nodeUuid);
} finally {
notificationService.emitEndModificationEquipmentNotification(studyUuid, nodeUuid, childrenUuids);
}
Expand Down

0 comments on commit d5a1d36

Please sign in to comment.