Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
f5553f3
export study
ghazwarhili Aug 7, 2026
c22592d
add TU
ghazwarhili Aug 7, 2026
84ff55c
enhance coverage code
ghazwarhili Aug 7, 2026
aa595a3
rework exportStudyArchive()
etiennehomer Aug 7, 2026
db1e926
code review remarks
ghazwarhili Aug 7, 2026
e04ee14
remove BuildStatus
ghazwarhili Aug 7, 2026
34e39f6
update TU
ghazwarhili Aug 7, 2026
7b241aa
add index
ghazwarhili Aug 10, 2026
6b0c1c8
Merge branch 'main' into razwa/export-study
ghazwarhili Aug 10, 2026
2ca0b42
remove CaseExportInfos
ghazwarhili Aug 10, 2026
115841b
Merge branch 'main' into razwa/export-study
ghazwarhili Aug 11, 2026
836cbfd
fix sonar issues
ghazwarhili Aug 11, 2026
83bb25b
code review Etienne L
ghazwarhili Aug 11, 2026
107d377
enhance TU
ghazwarhili Aug 11, 2026
ca94ad3
import study
ghazwarhili Aug 11, 2026
a217703
simplify the studyentity creation
ghazwarhili Aug 12, 2026
4c79e99
add TU
ghazwarhili Aug 12, 2026
43b9d7d
resolve conflicts
ghazwarhili Aug 13, 2026
ae80bc2
revert useless changes
ghazwarhili Aug 13, 2026
53a1e22
revert useless changes
ghazwarhili Aug 13, 2026
cf2cda1
revert useless changes
ghazwarhili Aug 13, 2026
6223d03
add StudyImportService
ghazwarhili Aug 14, 2026
b1fb871
resolve conflicts
ghazwarhili Aug 14, 2026
67b9307
code review rabbit
ghazwarhili Aug 14, 2026
f504693
enhance comments
ghazwarhili Aug 17, 2026
7742935
revert
ghazwarhili Aug 17, 2026
f613fb4
renaming fix
ghazwarhili Aug 17, 2026
05f683e
resolve conflicts
ghazwarhili Aug 28, 2026
9dfe44c
Fix merge
etiennehomer Aug 31, 2026
51776b7
resolve conflicts
ghazwarhili Sep 1, 2026
d3c6cb8
code review remarks
ghazwarhili Sep 4, 2026
df48eb0
revert unused changes
ghazwarhili Sep 4, 2026
52c67f8
Merge branch 'main' into razwa/import-study
ghazwarhili Sep 4, 2026
15797be
code review remarks
ghazwarhili Sep 4, 2026
d8e6c85
clean code
ghazwarhili Sep 4, 2026
4d85977
add emitStudyCreationFinished
ghazwarhili Sep 4, 2026
61f2dd2
fix test
ghazwarhili Sep 4, 2026
91b55b3
Merge branch 'main' into razwa/import-study
ghazwarhili Sep 7, 2026
14d9d7b
clean code
ghazwarhili Sep 7, 2026
fae45b0
Merge branch 'main' into razwa/import-study
ghazwarhili Sep 7, 2026
a4caf4d
fix merge
ghazwarhili Sep 7, 2026
92964ef
code review remarks part 1
ghazwarhili Sep 10, 2026
56a783d
code review part 2
ghazwarhili Sep 11, 2026
c2e2a97
Merge branch 'main' into razwa/import-study
ghazwarhili Sep 11, 2026
a4c11be
fix sonar issues
ghazwarhili Sep 11, 2026
6671a9c
Merge branch 'razwa/import-study' of https://github.com/gridsuite/stu…
ghazwarhili Sep 11, 2026
e3cffee
coe review rabbit
ghazwarhili Sep 14, 2026
369c687
Merge branch 'main' into razwa/import-study
ghazwarhili Sep 14, 2026
3035daf
refacto
ghazwarhili Sep 15, 2026
5e60233
fix TU
ghazwarhili Sep 15, 2026
b4ece94
fix TU
ghazwarhili Sep 15, 2026
71d4a80
Merge branch 'main' into razwa/import-study
ghazwarhili Sep 16, 2026
48134c0
fix bug index
ghazwarhili Sep 16, 2026
a92e2f1
Merge branch 'main' into razwa/import-study
ghazwarhili Sep 16, 2026
d71d07b
fix importStudy with Transactional
ghazwarhili Sep 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.gridsuite.study.server.dto.networkexport.ExportNetworkStatus;
import org.gridsuite.study.server.dto.networkexport.NodeExportInfos;
import org.gridsuite.study.server.dto.sequence.NodeSequenceType;
import org.gridsuite.study.server.dto.studyexport.TreeExportInfos;
import org.gridsuite.study.server.elasticsearch.EquipmentInfosService;
import org.gridsuite.study.server.error.StudyException;
import org.gridsuite.study.server.exception.PartialResultException;
Expand Down Expand Up @@ -70,6 +71,7 @@ public class StudyController {
private final NodeActivityRunnerService nodeActivityRunnerService;
private final NodeActivityService nodeActivityService;
private final StudyExportService studyExportService;
private final StudyImportService studyImportService;

public StudyController(StudyService studyService,
NetworkService networkStoreService,
Expand All @@ -82,7 +84,8 @@ public StudyController(StudyService studyService,
RebuildNodeService rebuildNodeService,
NodeActivityRunnerService nodeActivityRunnerService,
NodeActivityService nodeActivityService,
StudyExportService studyExportService) {
StudyExportService studyExportService,
StudyImportService studyImportService) {
this.nodeActivityService = nodeActivityService;
this.studyService = studyService;
this.networkModificationTreeService = networkModificationTreeService;
Expand All @@ -95,6 +98,7 @@ public StudyController(StudyService studyService,
this.rebuildNodeService = rebuildNodeService;
this.nodeActivityRunnerService = nodeActivityRunnerService;
this.studyExportService = studyExportService;
this.studyImportService = studyImportService;
}

@InitBinder
Expand Down Expand Up @@ -1640,4 +1644,13 @@ public ResponseEntity<Resource> exportStudy(@PathVariable("studyUuid") UUID stud
headers.setContentType(MediaType.parseMediaType("application/zip"));
return ResponseEntity.ok().headers(headers).body(studyExportService.exportStudy(studyUuid, userId));
}

@PostMapping(value = "/studies/import")
@Operation(summary = "Create a study and its root networks from a previously exported study archive")
@ApiResponse(responseCode = "200", description = "Study imported successfully")
public ResponseEntity<Void> importStudy(@RequestBody TreeExportInfos treeExportInfos,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
@RequestHeader(HEADER_USER_ID) String userId) {
studyImportService.importStudy(treeExportInfos, userId);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class ConsumerService {
private final LoadFlowService loadFlowService;
private final NodeActivityRunnerService nodeActivityRunnerService;
private final NodeActivityService nodeActivityService;
private final WorkspaceService workspaceService;

public ConsumerService(ObjectMapper objectMapper,
NotificationService notificationService,
Expand All @@ -94,7 +95,8 @@ public ConsumerService(ObjectMapper objectMapper,
UserAdminService userAdminService,
LoadFlowService loadFlowService,
NodeActivityRunnerService nodeActivityRunnerService,
NodeActivityService nodeActivityService) {
NodeActivityService nodeActivityService,
WorkspaceService workspaceService) {
this.objectMapper = objectMapper;
this.notificationService = notificationService;
this.studyService = studyService;
Expand All @@ -110,6 +112,7 @@ public ConsumerService(ObjectMapper objectMapper,
this.loadFlowService = loadFlowService;
this.nodeActivityService = nodeActivityService;
this.nodeActivityRunnerService = nodeActivityRunnerService;
this.workspaceService = workspaceService;
}

@Bean
Expand Down Expand Up @@ -292,73 +295,15 @@ private void insertStudy(UUID studyUuid, String userId, NetworkInfos networkInfo
UserProfileInfos userProfileInfos = studyService.getUserProfile(userId);

ComputationParameterUUIDs computationParameterUUIDs = computationParametersService.createDefaultComputationParameters(userId, userProfileInfos);
UUID networkVisualizationParametersUuid = createDefaultNetworkVisualizationParameters(userId, userProfileInfos);
UUID spreadsheetConfigCollectionUuid = createDefaultSpreadsheetConfigCollection(userId, userProfileInfos);
UUID workspacesConfigUuid = createWorkspacesConfig(userProfileInfos);
UUID networkVisualizationParametersUuid = studyConfigService.createDefaultNetworkVisualizationParameters(userId, userProfileInfos);
UUID spreadsheetConfigCollectionUuid = studyConfigService.createDefaultSpreadsheetConfigCollection(userId, userProfileInfos);
UUID workspacesConfigUuid = workspaceService.createWorkspacesConfig(userProfileInfos);

studyService.insertStudy(studyUuid, userId, networkInfos, caseInfos, computationParameterUUIDs,
networkVisualizationParametersUuid, spreadsheetConfigCollectionUuid, workspacesConfigUuid,
importParameters, importReportUuid);
}

private UUID createDefaultNetworkVisualizationParameters(String userId, UserProfileInfos userProfileInfos) {
if (userProfileInfos != null && userProfileInfos.getNetworkVisualizationParameterId() != null) {
// try to access/duplicate the user profile network visualization parameters

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not remove comment. The code should be fully unchanged for this methods !

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

try {
return studyConfigService.duplicateNetworkVisualizationParameters(userProfileInfos.getNetworkVisualizationParameterId());
} catch (Exception e) {
// TODO try to report a log in Root subreporter ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here !

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

LOGGER.error(String.format("Could not duplicate network visualization parameters with id '%s' from user/profile '%s/%s'. Using default parameters",
userProfileInfos.getNetworkVisualizationParameterId(), userId, userProfileInfos.getName()), e);
}
}
// no profile, or no/bad network visualization parameters in profile => use default values
try {
return studyConfigService.createDefaultNetworkVisualizationParameters();
} catch (final Exception e) {
LOGGER.error("Error while creating network visualization default parameters", e);
return null;
}
}

private UUID createDefaultSpreadsheetConfigCollection(String userId, UserProfileInfos userProfileInfos) {
if (userProfileInfos != null && userProfileInfos.getSpreadsheetConfigCollectionId() != null) {
// try to access/duplicate the user profile spreadsheet config collection
try {
return studyConfigService.duplicateSpreadsheetConfigCollection(userProfileInfos.getSpreadsheetConfigCollectionId());
} catch (Exception e) {
// TODO try to report a log in Root subreporter ?
LOGGER.error(String.format("Could not duplicate spreadsheet config collection with id '%s' from user/profile '%s/%s'. Using default spreadsheet config collection",
userProfileInfos.getSpreadsheetConfigCollectionId(), userId, userProfileInfos.getName()), e);
}
}
// no profile, or no/bad spreadsheet config collection in profile => use default values
try {
return studyConfigService.createDefaultSpreadsheetConfigCollection();
} catch (final Exception e) {
LOGGER.error("Error while creating default spreadsheet config collection", e);
return null;
}
}

@SuppressWarnings("checkstyle:LambdaBodyLength")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep the same code

private UUID createWorkspacesConfig(UserProfileInfos userProfileInfos) {
try {
List<UUID> workspaceIds = new ArrayList<>();
if (userProfileInfos != null && userProfileInfos.getWorkspaceId() != null) {
// Create config with profile workspace as first, and two empty workspaces

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

workspaceIds.add(userProfileInfos.getWorkspaceId());
workspaceIds.add(null);
workspaceIds.add(null);
}
// Empty list will create default config
return studyConfigService.createWorkspacesConfigFromWorkspaces(workspaceIds);
} catch (final Exception e) {
LOGGER.error("Error while creating workspace collection", e);
return null;
}
}

@Bean
@SuppressWarnings("checkstyle:LambdaBodyLength")
public Consumer<Message<String>> consumeCaseImportFailed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

import lombok.Setter;
import org.gridsuite.study.server.RemoteServicesProperties;
import org.gridsuite.study.server.dto.UserProfileInfos;
import org.gridsuite.study.server.repository.StudyEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
Expand All @@ -29,6 +32,7 @@
*/
@Service
public class StudyConfigService {
private static final Logger LOGGER = LoggerFactory.getLogger(StudyConfigService.class);
private static final String UUID_PARAM = "/{uuid}";

private static final String NETWORK_VISU_PARAMETERS_URI = "/network-visualizations-params";
Expand Down Expand Up @@ -456,4 +460,40 @@
.buildAndExpand().toUriString();
return restTemplate.exchange(studyConfigServerBaseUri + path, HttpMethod.POST, null, UUID.class).getBody();
}

public UUID createDefaultNetworkVisualizationParameters(String userId, UserProfileInfos userProfileInfos) {
if (userProfileInfos != null && userProfileInfos.getNetworkVisualizationParameterId() != null) {
// try to access/duplicate the user profile network visualization parameters
try {
return duplicateNetworkVisualizationParameters(userProfileInfos.getNetworkVisualizationParameterId());
} catch (Exception e) {
LOGGER.error(String.format("Could not duplicate network visualization parameters with id '%s' from user/profile '%s/%s'. Using default parameters",
userProfileInfos.getNetworkVisualizationParameterId(), userId, userProfileInfos.getName()), e);
}
}
try {
return createDefaultNetworkVisualizationParameters();
} catch (final Exception e) {
// TODO try to report a log in Root subreporter ?

Check warning on line 477 in src/main/java/org/gridsuite/study/server/service/StudyConfigService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this TODO comment.

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Astudy-server&issues=AaClC6ngWcawK7aMxUEt&open=AaClC6ngWcawK7aMxUEt&pullRequest=1057
LOGGER.error("Error while creating network visualization default parameters", e);
return null;
}
}

public UUID createDefaultSpreadsheetConfigCollection(String userId, UserProfileInfos userProfileInfos) {
if (userProfileInfos != null && userProfileInfos.getSpreadsheetConfigCollectionId() != null) {
try {
return duplicateSpreadsheetConfigCollection(userProfileInfos.getSpreadsheetConfigCollectionId());
} catch (Exception e) {
LOGGER.error(String.format("Could not duplicate spreadsheet config collection with id '%s' from user/profile '%s/%s'. Using default spreadsheet config collection",
userProfileInfos.getSpreadsheetConfigCollectionId(), userId, userProfileInfos.getName()), e);
}
}
try {
return createDefaultSpreadsheetConfigCollection();
} catch (final Exception e) {
LOGGER.error("Error while creating default spreadsheet config collection", e);
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Copyright (c) 2026, 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.service;

import org.gridsuite.study.server.dto.CaseInfos;
import org.gridsuite.study.server.dto.NetworkInfos;
import org.gridsuite.study.server.dto.RootNetworkInfos;
import org.gridsuite.study.server.dto.RootNetworkLoadStatus;
import org.gridsuite.study.server.dto.studyexport.RootNetworkExportInfos;
import org.gridsuite.study.server.dto.studyexport.TreeExportInfos;
import org.gridsuite.study.server.notification.NotificationService;
import org.gridsuite.study.server.repository.StudyEntity;
import org.gridsuite.study.server.repository.rootnetwork.RootNetworkEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
* @author Ghazwa Rehili <ghazwa.rehili at rte-france.com>
*/
@Service
public class StudyImportService {
private static final Logger LOGGER = LoggerFactory.getLogger(StudyImportService.class);

private final StudyService studyService;
private final RootNetworkService rootNetworkService;
private final CaseService caseService;
private final NotificationService notificationService;

public StudyImportService(StudyService studyService, RootNetworkService rootNetworkService,
CaseService caseService, NotificationService notificationService) {
this.studyService = studyService;
this.rootNetworkService = rootNetworkService;
this.caseService = caseService;
this.notificationService = notificationService;
}

@Transactional
public void importStudy(TreeExportInfos treeExportInfos, String userId) {
StudyEntity studyEntity = createStudyEntityWithTree(treeExportInfos, userId);
UUID studyUuid = studyEntity.getId();
duplicateCaseAndCreateRootNetworks(studyUuid, treeExportInfos.rootNetworks());
notificationService.emitStudyCreationFinished(studyUuid, userId);
}

public StudyEntity createStudyEntityWithTree(TreeExportInfos treeExportInfos, String userId) {
return studyService.createStudyEntityWithTree(treeExportInfos.studyUuid(), userId, treeExportInfos.nodeTree());
}

public void duplicateCaseAndCreateRootNetworks(UUID studyUuid, List<RootNetworkExportInfos> rootNetworksInfos) {
List<RootNetworkExportInfos> orderedRootNetworks = rootNetworksInfos.stream().sorted(Comparator.comparing(RootNetworkExportInfos::index)).toList();
for (RootNetworkExportInfos rootNetworkInfos : orderedRootNetworks) {
UUID newCaseUuid = caseService.duplicateCase(rootNetworkInfos.caseInfos().getCaseUuid(), false);
try {
createRootNetwork(studyUuid, rootNetworkInfos, newCaseUuid);
} catch (Exception exception) {
caseService.deleteCase(newCaseUuid);
LOGGER.error(String.format("Could not clean up orphaned case '%s' after import failure", newCaseUuid), exception);
}
}
}

public void createRootNetwork(UUID studyUuid, RootNetworkExportInfos rootNetworkInfos, UUID newCaseUuid) {
StudyEntity studyEntity = studyService.getStudy(studyUuid);
RootNetworkEntity rootNetworkEntity = rootNetworkService.createRootNetwork(studyEntity, RootNetworkInfos.builder()
.id(UUID.randomUUID())
.name(rootNetworkInfos.name())
.tag(rootNetworkInfos.tag())
.caseInfos(new CaseInfos(newCaseUuid, rootNetworkInfos.caseInfos().getOriginalCaseUuid(),
rootNetworkInfos.caseInfos().getCaseName(), rootNetworkInfos.caseInfos().getCaseFormat()))
.importParameters(rootNetworkInfos.importParameters())
.networkInfos(new NetworkInfos(UUID.randomUUID(), ""))
.build());
rootNetworkService.updateNetworkLoadStatus(rootNetworkEntity.getId(), RootNetworkLoadStatus.UNLOADED);
}
}
Loading
Loading