-
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
base: main
Are you sure you want to change the base?
import study #1057
Changes from 22 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
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 |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| import org.gridsuite.study.server.repository.voltageinit.StudyVoltageInitParametersEntity; | ||
|
|
||
| import java.util.*; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com> | ||
|
|
@@ -36,6 +37,18 @@ public class StudyEntity extends AbstractManuallyAssignedIdentifierEntity<UUID> | |
| @Builder.Default | ||
| private List<RootNetworkEntity> rootNetworks = new ArrayList<>(); | ||
|
|
||
| /** | ||
| * Desired order of root network ids for an in-progress batch import (they can complete out of order). | ||
| * Used by {@link #addRootNetwork(RootNetworkEntity)} to place each one correctly; cleared once done. | ||
| */ | ||
| @ElementCollection | ||
| @CollectionTable(name = "StudyRootNetworkOrder", foreignKey = @ForeignKey( | ||
| name = "study_root_network_order_fk" | ||
| )) | ||
| @OrderColumn(name = "index") | ||
| @Column(name = "rootNetworkUuid") | ||
| private List<UUID> rootNetworkOrder; | ||
|
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. Why that ? you have an index in root_network table
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. not needed anymore |
||
|
|
||
| /** | ||
| * @deprecated to remove when the data is migrated into the loadflow-server | ||
| */ | ||
|
|
@@ -140,7 +153,21 @@ public RootNetworkEntity getFirstRootNetwork() { | |
| public void addRootNetwork(RootNetworkEntity rootNetworkEntity) { | ||
| rootNetworkEntity.setStudy(this); | ||
| rootNetworkEntity.setIndexationStatus(RootNetworkIndexationStatus.INDEXED); | ||
| rootNetworks.add(rootNetworkEntity); | ||
| rootNetworks.add(resolveInsertPosition(rootNetworkEntity.getId()), rootNetworkEntity); | ||
| } | ||
|
|
||
| /** | ||
| * Position among the root networks already present, for the given target id: the count of ids that | ||
| * should come before it in {@link #rootNetworkOrder} and are already in {@link #rootNetworks}. Falls back | ||
| * to appending at the end when there is no pending import batch, or the id isn't part of one. | ||
| */ | ||
| private int resolveInsertPosition(UUID rootNetworkId) { | ||
|
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. insert with same indexes. THis is 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. not needed anymore |
||
| int targetPos = rootNetworkOrder == null ? -1 : rootNetworkOrder.indexOf(rootNetworkId); | ||
| if (targetPos < 0) { | ||
| return rootNetworks.size(); | ||
| } | ||
| Set<UUID> alreadyPresent = rootNetworks.stream().map(RootNetworkEntity::getId).collect(Collectors.toSet()); | ||
| return (int) rootNetworkOrder.subList(0, targetPos).stream().filter(alreadyPresent::contains).count(); | ||
| } | ||
|
|
||
| public void deleteRootNetworks(Set<UUID> uuids) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,12 +16,16 @@ | |
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.http.HttpMethod; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.http.client.ClientHttpResponse; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.web.client.ResourceAccessException; | ||
| import org.springframework.web.client.RestTemplate; | ||
| import org.springframework.web.util.UriComponentsBuilder; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.util.UUID; | ||
|
|
||
| import static org.gridsuite.study.server.StudyConstants.CASE_API_VERSION; | ||
|
|
@@ -96,11 +100,26 @@ public UUID createCase(String caseKey, String contentType) { | |
| return restTemplate.exchange(caseServerBaseUri + path, HttpMethod.POST, null, UUID.class).getBody(); | ||
| } | ||
|
|
||
| public ResponseEntity<byte[]> getCaseContent(UUID caseUuid) { | ||
| public void streamCaseContent(UUID caseUuid, CaseContentHandler handler) throws IOException { | ||
| String path = UriComponentsBuilder.fromPath(DELIMITER + CASE_API_VERSION + "/cases/{caseUuid}") | ||
| .buildAndExpand(caseUuid) | ||
| .toUriString(); | ||
|
|
||
| return restTemplate.exchange(caseServerBaseUri + path, HttpMethod.GET, null, byte[].class); | ||
| try { | ||
| restTemplate.execute(caseServerBaseUri + path, HttpMethod.GET, null, (ClientHttpResponse response) -> { | ||
| handler.handle(response.getHeaders().getFirst(HttpHeaders.CONTENT_ENCODING), response.getBody()); | ||
| return null; | ||
| }); | ||
| } catch (ResourceAccessException e) { | ||
| if (e.getCause() instanceof IOException ioException) { | ||
| throw ioException; | ||
| } | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| @FunctionalInterface | ||
|
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. better create a new PR for export changes And here, why this change ? The handler is needed ? |
||
| public interface CaseContentHandler { | ||
| void handle(String contentEncoding, InputStream body) throws IOException; | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,10 +66,10 @@ public class ConsumerService { | |
|
|
||
| private final NotificationService notificationService; | ||
| private final StudyService studyService; | ||
| private final StudyImportService studyImportService; | ||
| 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; | ||
|
|
@@ -79,10 +79,10 @@ public class ConsumerService { | |
| public ConsumerService(ObjectMapper objectMapper, | ||
| NotificationService notificationService, | ||
| StudyService studyService, | ||
| StudyImportService studyImportService, | ||
| CaseService caseService, | ||
| LoadFlowRestService loadFlowRestService, | ||
| NetworkModificationTreeService networkModificationTreeService, | ||
| StudyConfigService studyConfigService, | ||
| RootNetworkNodeInfoService rootNetworkNodeInfoService, | ||
| DirectoryService directoryService, | ||
| ComputationParametersService computationParametersService, | ||
|
|
@@ -91,10 +91,10 @@ public ConsumerService(ObjectMapper objectMapper, | |
| this.objectMapper = objectMapper; | ||
| this.notificationService = notificationService; | ||
| this.studyService = studyService; | ||
| this.studyImportService = studyImportService; | ||
| this.caseService = caseService; | ||
| this.loadFlowRestService = loadFlowRestService; | ||
| this.networkModificationTreeService = networkModificationTreeService; | ||
| this.studyConfigService = studyConfigService; | ||
| this.rootNetworkNodeInfoService = rootNetworkNodeInfoService; | ||
| this.directoryService = directoryService; | ||
| this.computationParametersService = computationParametersService; | ||
|
|
@@ -250,6 +250,16 @@ private void handleConsumeCaseImportSucceeded(CaseImportReceiver receiver, UUID | |
| .networkInfos(networkInfos) | ||
| .importParameters(importParameters) | ||
| .build()); | ||
| case ROOT_NETWORK_CREATION_FOR_STUDY_IMPORT -> { | ||
|
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. Why ROOT_NETWORK_CREATION_FOR_STUDY_IMPORT ?
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. not needed anymore |
||
| studyService.createRootNetwork(studyUuid, RootNetworkInfos.builder() | ||
| .id(rootNetworkUuid) | ||
| .caseInfos(caseInfos) | ||
| .reportUuid(importReportUuid) | ||
| .networkInfos(networkInfos) | ||
| .importParameters(importParameters) | ||
| .build()); | ||
| studyImportService.checkFinishedStudyImport(studyUuid, userId); | ||
| } | ||
| case NETWORK_RECREATION -> studyService.updateNetwork(studyUuid, rootNetworkUuid, networkInfos, userId); | ||
| case ROOT_NETWORK_MODIFICATION -> studyService.modifyRootNetwork(studyUuid, RootNetworkInfos.builder() | ||
| .id(rootNetworkUuid) | ||
|
|
@@ -281,73 +291,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() { | ||
|
|
@@ -364,12 +316,16 @@ public Consumer<Message<String>> consumeCaseImportFailed() { | |
| String userId = receiver.getUserId(); | ||
| UUID rootNetworkUuid = receiver.getRootNetworkUuid(); | ||
|
|
||
| if (receiver.getCaseImportAction() == CaseImportAction.STUDY_CREATION) { | ||
| CaseImportAction caseImportAction = receiver.getCaseImportAction(); | ||
| if (caseImportAction == CaseImportAction.STUDY_CREATION) { | ||
| studyService.deleteStudyIfNotCreationInProgress(studyUuid, userId); | ||
| notificationService.emitStudyCreationError(studyUuid, userId, errorMessage); | ||
| } else { | ||
| if (receiver.getCaseImportAction() == CaseImportAction.ROOT_NETWORK_CREATION) { | ||
| if (caseImportAction == CaseImportAction.ROOT_NETWORK_CREATION) { | ||
| studyService.deleteRootNetworkRequest(rootNetworkUuid); | ||
| } else if (caseImportAction == CaseImportAction.ROOT_NETWORK_CREATION_FOR_STUDY_IMPORT) { | ||
| studyService.deleteRootNetworkRequest(rootNetworkUuid); | ||
| studyImportService.checkFinishedStudyImport(studyUuid, userId); | ||
| } | ||
| notificationService.emitRootNetworksUpdateFailed(studyUuid, errorMessage); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.