-
Notifications
You must be signed in to change notification settings - Fork 2
import study #1057
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
import study #1057
Changes from all commits
f5553f3
c22592d
84ff55c
aa595a3
db1e926
e04ee14
34e39f6
7b241aa
6b0c1c8
2ca0b42
115841b
836cbfd
83bb25b
107d377
ca94ad3
a217703
4c79e99
43b9d7d
ae80bc2
53a1e22
cf2cda1
6223d03
b1fb871
67b9307
f504693
7742935
f613fb4
05f683e
9dfe44c
51776b7
d3c6cb8
df48eb0
52c67f8
15797be
d8e6c85
4d85977
61f2dd2
91b55b3
14d9d7b
fae45b0
a4caf4d
92964ef
56a783d
c2e2a97
a4c11be
6671a9c
e3cffee
369c687
3035daf
5e60233
b4ece94
71d4a80
48134c0
a92e2f1
d71d07b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -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; | ||
|
|
@@ -110,6 +112,7 @@ public ConsumerService(ObjectMapper objectMapper, | |
| this.loadFlowService = loadFlowService; | ||
| this.nodeActivityService = nodeActivityService; | ||
| this.nodeActivityRunnerService = nodeActivityRunnerService; | ||
| this.workspaceService = workspaceService; | ||
| } | ||
|
|
||
| @Bean | ||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 !
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here !
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same with comment
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
|
|
||
| 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); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.