19
19
import org .gridsuite .study .server .StudyConstants ;
20
20
import org .gridsuite .study .server .StudyException ;
21
21
import org .gridsuite .study .server .dto .*;
22
- import org .gridsuite .study .server .dto .InvalidateNodeTreeParameters .ComputationsInvalidationMode ;
23
- import org .gridsuite .study .server .dto .InvalidateNodeTreeParameters .InvalidationMode ;
24
22
import org .gridsuite .study .server .dto .caseimport .CaseImportAction ;
25
23
import org .gridsuite .study .server .dto .dynamicmapping .MappingInfos ;
26
24
import org .gridsuite .study .server .dto .dynamicmapping .ModelInfos ;
@@ -1901,9 +1899,7 @@ public void deleteNetworkModifications(UUID studyUuid, UUID nodeUuid, List<UUID>
1901
1899
UUID groupId = networkModificationTreeService .getModificationGroupUuid (nodeUuid );
1902
1900
networkModificationService .deleteModifications (groupId , modificationsUuids );
1903
1901
// for each root network, remove modifications from excluded ones
1904
- studyEntity .getRootNetworks ().forEach (rootNetworkEntity -> {
1905
- rootNetworkNodeInfoService .updateModificationsToExclude (nodeUuid , rootNetworkEntity .getId (), new HashSet <>(modificationsUuids ), true );
1906
- });
1902
+ studyEntity .getRootNetworks ().forEach (rootNetworkEntity -> rootNetworkNodeInfoService .updateModificationsToExclude (nodeUuid , rootNetworkEntity .getId (), new HashSet <>(modificationsUuids ), true ));
1907
1903
} finally {
1908
1904
notificationService .emitEndDeletionEquipmentNotification (studyUuid , nodeUuid , childrenUuids );
1909
1905
}
@@ -2850,6 +2846,9 @@ public String getNetworkElementsIds(UUID nodeUuid, UUID rootNetworkUuid, List<St
2850
2846
public String getVoltageInitModifications (@ NonNull UUID nodeUuid , @ NonNull UUID rootNetworkUuid ) {
2851
2847
// get modifications group uuid associated to voltage init results
2852
2848
UUID resultUuid = rootNetworkNodeInfoService .getComputationResultUuid (nodeUuid , rootNetworkUuid , ComputationType .VOLTAGE_INITIALIZATION );
2849
+ if (resultUuid == null ) {
2850
+ throw new StudyException (NO_VOLTAGE_INIT_RESULTS_FOR_NODE , String .format ("Missing results for rootNetwork %s on node %s" , rootNetworkUuid , nodeUuid ));
2851
+ }
2853
2852
UUID voltageInitModificationsGroupUuid = voltageInitService .getModificationsGroupUuid (nodeUuid , resultUuid );
2854
2853
return networkModificationService .getModifications (voltageInitModificationsGroupUuid , false , false );
2855
2854
}
@@ -2858,23 +2857,37 @@ public String getVoltageInitModifications(@NonNull UUID nodeUuid, @NonNull UUID
2858
2857
public void insertVoltageInitModifications (UUID studyUuid , UUID nodeUuid , UUID rootNetworkUuid , String userId ) {
2859
2858
// get modifications group uuid associated to voltage init results
2860
2859
UUID resultUuid = rootNetworkNodeInfoService .getComputationResultUuid (nodeUuid , rootNetworkUuid , ComputationType .VOLTAGE_INITIALIZATION );
2861
- UUID voltageInitModificationsGroupUuid = voltageInitService .getModificationsGroupUuid (nodeUuid , resultUuid );
2862
- if (voltageInitModificationsGroupUuid == null ) {
2863
- return ;
2860
+ if (resultUuid == null ) {
2861
+ throw new StudyException (NO_VOLTAGE_INIT_RESULTS_FOR_NODE , String .format ("Missing results for rootNetwork %s on node %s" , rootNetworkUuid , nodeUuid ));
2864
2862
}
2863
+ UUID voltageInitModificationsGroupUuid = voltageInitService .getModificationsGroupUuid (nodeUuid , resultUuid );
2865
2864
2866
2865
List <UUID > childrenUuids = networkModificationTreeService .getChildrenUuids (nodeUuid );
2867
2866
notificationService .emitStartModificationEquipmentNotification (studyUuid , nodeUuid , childrenUuids , NotificationService .MODIFICATIONS_UPDATING_IN_PROGRESS );
2868
2867
try {
2869
2868
checkStudyContainsNode (studyUuid , nodeUuid );
2870
2869
2870
+ // voltageInit modification should apply only on the root network where the computation has been made:
2871
+ // - application context will point to the computation root network only
2872
+ // - after creation, we deactivate the new modification for all other root networks
2871
2873
List <RootNetworkEntity > studyRootNetworkEntities = getStudyRootNetworks (studyUuid );
2872
- List <ModificationApplicationContext > modificationApplicationContexts = studyRootNetworkEntities .stream ()
2873
- .map (rootNetworkEntity -> rootNetworkNodeInfoService .getNetworkModificationApplicationContext (rootNetworkEntity .getId (), nodeUuid , rootNetworkEntity .getNetworkUuid ()))
2874
- .toList ();
2874
+ List <ModificationApplicationContext > modificationApplicationContexts = new ArrayList <>();
2875
+ List <UUID > rootNetworkToDeactivateUuids = new ArrayList <>();
2876
+ studyRootNetworkEntities .forEach (rootNetworkEntity -> {
2877
+ if (rootNetworkUuid .equals (rootNetworkEntity .getId ())) {
2878
+ modificationApplicationContexts .add (rootNetworkNodeInfoService .getNetworkModificationApplicationContext (rootNetworkEntity .getId (), nodeUuid , rootNetworkEntity .getNetworkUuid ()));
2879
+ } else {
2880
+ rootNetworkToDeactivateUuids .add (rootNetworkEntity .getId ());
2881
+ }
2882
+ });
2883
+ // duplicate the modification created by voltageInit server into the current node
2875
2884
NetworkModificationsResult networkModificationResults = networkModificationService .duplicateModificationsFromGroup (networkModificationTreeService .getModificationGroupUuid (nodeUuid ), voltageInitModificationsGroupUuid , Pair .of (List .of (), modificationApplicationContexts ));
2876
2885
2877
- if (networkModificationResults != null ) {
2886
+ // We expect a single voltageInit modification in the result list
2887
+ if (networkModificationResults != null && networkModificationResults .modificationUuids ().size () == 1 ) {
2888
+ for (UUID otherRootNetwork : rootNetworkToDeactivateUuids ) {
2889
+ rootNetworkNodeInfoService .updateModificationsToExclude (nodeUuid , otherRootNetwork , Set .of (networkModificationResults .modificationUuids ().getFirst ()), false );
2890
+ }
2878
2891
int index = 0 ;
2879
2892
// for each NetworkModificationResult, send an impact notification - studyRootNetworkEntities are ordered in the same way as networkModificationResults
2880
2893
for (Optional <NetworkModificationResult > modificationResultOpt : networkModificationResults .modificationResults ()) {
@@ -2885,7 +2898,7 @@ public void insertVoltageInitModifications(UUID studyUuid, UUID nodeUuid, UUID r
2885
2898
}
2886
2899
}
2887
2900
2888
- voltageInitService .resetModificationsGroupUuid (nodeUuid , resultUuid );
2901
+ voltageInitService .resetModificationsGroupUuid (resultUuid );
2889
2902
2890
2903
// invalidate the whole subtree except the target node (we have built this node during the duplication)
2891
2904
notificationService .emitStudyChanged (studyUuid , nodeUuid , rootNetworkUuid , NotificationService .UPDATE_TYPE_VOLTAGE_INIT_RESULT ); // send notification voltage init result has changed
0 commit comments