@@ -104,10 +104,10 @@ public CriticalBranchReader(List<TBranch> tBranches, @Nullable TOutage tOutage,
104
104
this .criticalBranchImportStatus = ImportStatus .INCOMPLETE_DATA ;
105
105
this .invalidBranchReason = String .format ("CNEC is defined on outage %s which is not defined" , outage );
106
106
} else {
107
- this .isImported = true ;
108
107
this .isDirectionInverted = branchHelper .isInvertedInNetwork ();
109
108
this .selected = !isMonitored && isSelected (tBranch );
110
109
if (tOutage == null ) {
110
+ this .isImported = true ;
111
111
// preventive
112
112
this .isBaseCase = true ;
113
113
this .contingencyId = null ;
@@ -117,8 +117,14 @@ public CriticalBranchReader(List<TBranch> tBranches, @Nullable TOutage tOutage,
117
117
// curative
118
118
this .isBaseCase = false ;
119
119
this .contingencyId = outage ;
120
- this .criticalBranchImportStatus = ImportStatus .IMPORTED ;
121
- importCurativeCnecs (tBranch , branchHelper , outage , crac , isMonitored );
120
+ if (importCurativeCnecs (tBranch , branchHelper , outage , crac , isMonitored )) {
121
+ this .criticalBranchImportStatus = ImportStatus .IMPORTED ;
122
+ this .isImported = true ;
123
+ } else {
124
+ this .criticalBranchImportStatus = ImportStatus .INCOMPLETE_DATA ;
125
+ this .invalidBranchReason = "Incomplete Imax data to create at least one preventive CNEC for the branch." ;
126
+ this .isImported = false ;
127
+ }
122
128
}
123
129
}
124
130
}
@@ -134,12 +140,37 @@ private void importPreventiveCnec(TBranch tBranch, UcteFlowElementHelper branchH
134
140
importCnec (crac , tBranch , branchHelper , isMonitored ? tBranch .getIlimitMNE () : tBranch .getImax (), null , crac .getPreventiveInstant ().getId (), isMonitored );
135
141
}
136
142
137
- private void importCurativeCnecs (TBranch tBranch , UcteFlowElementHelper branchHelper , String outage , Crac crac , boolean isMonitored ) {
143
+ /**
144
+ * Returns true if at least one CNEC has been correctly imported.
145
+ * @param tBranch
146
+ * @param branchHelper
147
+ * @param outage
148
+ * @param crac
149
+ * @param isMonitored
150
+ * @return
151
+ */
152
+ private boolean importCurativeCnecs (TBranch tBranch , UcteFlowElementHelper branchHelper , String outage , Crac crac , boolean isMonitored ) {
138
153
HashMap <Instant , TImax > cnecCaracs = new HashMap <>();
139
154
cnecCaracs .put (crac .getOutageInstant (), isMonitored ? tBranch .getIlimitMNEAfterOutage () : tBranch .getImaxAfterOutage ());
140
- cnecCaracs .put (crac .getInstant (InstantKind .AUTO ), isMonitored ? tBranch .getIlimitMNEAfterSPS () : tBranch . getImaxAfterSPS ( ));
141
- cnecCaracs .put (crac .getInstant (InstantKind .CURATIVE ), isMonitored ? tBranch .getIlimitMNEAfterCRA () : tBranch .getImaxAfterCRA ());
155
+ cnecCaracs .put (crac .getInstant (InstantKind .AUTO ), isMonitored ? tBranch .getIlimitMNEAfterSPS () : findTargetImaxAfterSPS ( tBranch ));
156
+ cnecCaracs .put (crac .getInstant (InstantKind .CURATIVE ), isMonitored ? tBranch .getIlimitMNEAfterCRA () : findTargetImaxAfterCRA ( tBranch .getImaxAfterCRA () ));
142
157
cnecCaracs .forEach ((instant , iMax ) -> importCnec (crac , tBranch , branchHelper , iMax , outage , instant .getId (), isMonitored ));
158
+ return cnecCaracs .values ().stream ().anyMatch (Objects ::nonNull );
159
+ }
160
+
161
+ private TImax findTargetImaxAfterCRA (final TImax imaxAfterCRA ) {
162
+ return imaxAfterCRA != null ? imaxAfterCRA : createDefaultImaxAfterCRA ();
163
+ }
164
+
165
+ private TImax createDefaultImaxAfterCRA () {
166
+ final TImax tempImax = new TImax ();
167
+ tempImax .setUnit ("Pct" );
168
+ tempImax .setV ((short ) 100 );
169
+ return tempImax ;
170
+ }
171
+
172
+ private TImax findTargetImaxAfterSPS (final TBranch tBranch ) {
173
+ return tBranch .getImaxAfterSPS () != null ? tBranch .getImaxAfterSPS () : tBranch .getImaxAfterOutage ();
143
174
}
144
175
145
176
private void importCnec (Crac crac , TBranch tBranch , UcteFlowElementHelper branchHelper , @ Nullable TImax tImax , String outage , String instantId , boolean isMonitored ) {
0 commit comments