Skip to content
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
41 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
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 @@ -1615,4 +1616,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-with-case-import-action")
@Operation(summary = "Create a study and its root networks from a previously exported study archive")
@ApiResponse(responseCode = "200", description = "Study import initiated successfully")
public ResponseEntity<Void> importStudyWithCaseImportAction(@RequestBody TreeExportInfos treeExportInfos,
@RequestHeader(HEADER_USER_ID) String userId) {
studyService.importStudyWithCaseImportAction(treeExportInfos, userId);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public class ConsumerService {
private final CaseService caseService;
private final LoadFlowRestService loadFlowRestService;
private final NetworkModificationTreeService networkModificationTreeService;
private final StudyConfigService studyConfigService;
private final RootNetworkNodeInfoService rootNetworkNodeInfoService;
private final DirectoryService directoryService;
private final ComputationParametersService computationParametersService;
Expand All @@ -82,7 +81,6 @@ public ConsumerService(ObjectMapper objectMapper,
CaseService caseService,
LoadFlowRestService loadFlowRestService,
NetworkModificationTreeService networkModificationTreeService,
StudyConfigService studyConfigService,
RootNetworkNodeInfoService rootNetworkNodeInfoService,
DirectoryService directoryService,
ComputationParametersService computationParametersService,
Expand All @@ -94,7 +92,6 @@ public ConsumerService(ObjectMapper objectMapper,
this.caseService = caseService;
this.loadFlowRestService = loadFlowRestService;
this.networkModificationTreeService = networkModificationTreeService;
this.studyConfigService = studyConfigService;
this.rootNetworkNodeInfoService = rootNetworkNodeInfoService;
this.directoryService = directoryService;
this.computationParametersService = computationParametersService;
Expand Down Expand Up @@ -241,8 +238,7 @@ private void handleConsumeCaseImportSucceeded(CaseImportReceiver receiver, UUID
NetworkInfos networkInfos = new NetworkInfos(networkUuid, networkId);
try {
switch (caseImportAction) {
case STUDY_CREATION ->
insertStudy(studyUuid, userId, networkInfos, caseInfos, importParameters, importReportUuid);
case STUDY_CREATION -> insertStudy(studyUuid, userId, networkInfos, caseInfos, importParameters, importReportUuid);
case ROOT_NETWORK_CREATION -> studyService.createRootNetwork(studyUuid, RootNetworkInfos.builder()
.id(rootNetworkUuid)
.caseInfos(caseInfos)
Expand Down Expand Up @@ -281,73 +277,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 = studyService.createDefaultNetworkVisualizationParameters(userId, userProfileInfos);
UUID spreadsheetConfigCollectionUuid = studyService.createDefaultSpreadsheetConfigCollection(userId, userProfileInfos);
UUID workspacesConfigUuid = studyService.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
try {
return studyConfigService.duplicateNetworkVisualizationParameters(userProfileInfos.getNetworkVisualizationParameterId());
} catch (Exception e) {
// TODO try to report a log in Root subreporter ?
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")
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
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
151 changes: 151 additions & 0 deletions src/main/java/org/gridsuite/study/server/service/StudyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3067,4 +3067,155 @@
children
);
}

private NetworkModificationNodeType toNetworkModificationNodeType(String nodeType) {
if (nodeType == null) {
throw new StudyException(BAD_NODE_TYPE, "Missing node type in imported tree");
}
try {
return NetworkModificationNodeType.valueOf(nodeType);
} catch (IllegalArgumentException e) {

Check warning on line 3077 in src/main/java/org/gridsuite/study/server/service/StudyService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace "e" with an unnamed pattern.

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Astudy-server&issues=AZ_2i3PebuvzarwK2m6e&open=AZ_2i3PebuvzarwK2m6e&pullRequest=1057
throw new StudyException(BAD_NODE_TYPE, "Invalid node type in imported tree: '" + nodeType + "'");
}
}

private RootNetworkInfos toRootNetworkInfos(RootNetworkExportInfos rootNetworkExportInfos) {
CaseInfos caseInfos = rootNetworkExportInfos.caseInfos();
return RootNetworkInfos.builder()
.name(rootNetworkExportInfos.name())
.tag(rootNetworkExportInfos.tag())
.caseInfos(new CaseInfos(null, caseInfos.getCaseUuid(), caseInfos.getCaseName(), caseInfos.getCaseFormat()))
.importParameters(rootNetworkExportInfos.importParameters())
.build();
}

public void importStudyWithCaseImportAction(TreeExportInfos treeExportInfos, String userId) {
if (treeExportInfos.rootNetworks().isEmpty()) {
throw new StudyException(NOT_FOUND, "No root network found in import archive");
}
List<RootNetworkExportInfos> orderedRootNetworks = treeExportInfos.rootNetworks().stream()
.sorted(Comparator.comparing(RootNetworkExportInfos::index))
.toList();

StudyEntity studyEntity = self.createStudyEntityWithTree(treeExportInfos.studyUuid(), userId, treeExportInfos.nodeTree());

orderedRootNetworks.forEach(rootNetwork -> {
try {
caseService.assertCaseExists(rootNetwork.caseInfos().getCaseUuid());
self.createRootNetworkRequest(studyEntity.getId(), toRootNetworkInfos(rootNetwork), userId);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
} catch (Exception e) {
LOGGER.error(String.format("Could not request root network '%s' for imported study '%s'", rootNetwork.name(), studyEntity.getId()), e);
}
});

notificationService.emitStudyCreationFinished(studyEntity.getId(), userId);
}

@Transactional
StudyEntity createStudyEntityWithTree(UUID studyUuid, String userId, NodeTreeExportInfos nodeTree) {
UserProfileInfos userProfileInfos = getUserProfile(userId);
ComputationParameterUUIDs computationParameterUUIDs = computationParametersService.createDefaultComputationParameters(userId, userProfileInfos);
UUID networkVisualizationParametersUuid = createDefaultNetworkVisualizationParameters(userId, userProfileInfos);
UUID spreadsheetConfigCollectionUuid = createDefaultSpreadsheetConfigCollection(userId, userProfileInfos);
UUID workspacesConfigUuid = createWorkspacesConfig(userProfileInfos);

StudyEntity studyEntity = studyRepository.save(StudyEntity.builder()
.id(studyUuid)
.loadFlowParametersUuid(computationParameterUUIDs.loadFlowParametersUuid())
.shortCircuitParametersUuid(computationParameterUUIDs.shortCircuitParametersUuid())
.voltageInitParametersUuid(computationParameterUUIDs.voltageInitParametersUuid())
.securityAnalysisParametersUuid(computationParameterUUIDs.securityAnalysisParametersUuid())
.sensitivityAnalysisParametersUuid(computationParameterUUIDs.sensitivityAnalysisParametersUuid())
.voltageInitParameters(new StudyVoltageInitParametersEntity())
.networkVisualizationParametersUuid(networkVisualizationParametersUuid)
.dynamicSimulationParametersUuid(computationParameterUUIDs.dynamicSimulationParametersUuid())
.dynamicSecurityAnalysisParametersUuid(computationParameterUUIDs.dynamicSecurityAnalysisParametersUuid())
.dynamicMarginCalculationParametersUuid(computationParameterUUIDs.dynamicMarginCalculationParametersUuid())
.stateEstimationParametersUuid(computationParameterUUIDs.stateEstimationParametersUuid())
.pccMinParametersUuid(computationParameterUUIDs.pccMinParametersUuid())
.spreadsheetConfigCollectionUuid(spreadsheetConfigCollectionUuid)
.workspacesConfigUuid(workspacesConfigUuid)
.monoRoot(true)
.build());

UUID rootNodeUuid = networkModificationTreeService.createRoot(studyEntity).getIdNode();
if (nodeTree != null && !nodeTree.children().isEmpty()) {
nodeTree.children().forEach(child -> createNodeRecursively(studyEntity, rootNodeUuid, child, userId));
}

studyInfosService.add(toCreatedStudyBasicInfos(studyEntity));

return studyEntity;
}

private void createNodeRecursively(StudyEntity studyEntity, UUID parentNodeUuid, NodeTreeExportInfos exportNode, String userId) {
NetworkModificationNodeType nodeType = toNetworkModificationNodeType(exportNode.nodeType());
UUID newGroupUuid = null;
if (exportNode.modificationGroupUuid() != null) {
newGroupUuid = UUID.randomUUID();
networkModificationService.duplicateModificationsGroup(exportNode.modificationGroupUuid(), newGroupUuid);
}
NetworkModificationNode newNode = networkModificationTreeService.createNode(
studyEntity,
parentNodeUuid,
NetworkModificationNode.builder()
.name(exportNode.name())
.nodeType(nodeType)
// buildStatus intentionally left by default (NOT_BUILT):
.modificationGroupUuid(newGroupUuid)
.build(),
InsertMode.CHILD,
userId
);
CollectionUtils.emptyIfNull(exportNode.children()).forEach(child -> createNodeRecursively(studyEntity, newNode.getId(), child, userId));
}

UUID createDefaultNetworkVisualizationParameters(String userId, UserProfileInfos userProfileInfos) {
if (userProfileInfos != null && userProfileInfos.getNetworkVisualizationParameterId() != null) {
try {
return studyConfigService.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 studyConfigService.createDefaultNetworkVisualizationParameters();
} catch (final Exception e) {
LOGGER.error("Error while creating network visualization default parameters", e);
return null;
}
}

UUID createDefaultSpreadsheetConfigCollection(String userId, UserProfileInfos userProfileInfos) {
if (userProfileInfos != null && userProfileInfos.getSpreadsheetConfigCollectionId() != null) {
try {
return studyConfigService.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 studyConfigService.createDefaultSpreadsheetConfigCollection();
} catch (final Exception e) {
LOGGER.error("Error while creating default spreadsheet config collection", e);
return null;
}
}

UUID createWorkspacesConfig(UserProfileInfos userProfileInfos) {
try {
List<UUID> workspaceIds = new ArrayList<>();
if (userProfileInfos != null && userProfileInfos.getWorkspaceId() != null) {
workspaceIds.add(userProfileInfos.getWorkspaceId());
workspaceIds.add(null);
workspaceIds.add(null);
}
return studyConfigService.createWorkspacesConfigFromWorkspaces(workspaceIds);
} catch (final Exception e) {
LOGGER.error("Error while creating workspace collection", e);
return null;
}
}
}
Loading
Loading