7
7
import lombok .Getter ;
8
8
import lombok .RequiredArgsConstructor ;
9
9
import lombok .extern .slf4j .Slf4j ;
10
+ import org .apache .commons .lang3 .StringUtils ;
10
11
import org .lfenergy .compas .scl2007b4 .model .*;
11
12
import org .lfenergy .compas .sct .commons .api .ExtRefEditor ;
12
13
import org .lfenergy .compas .sct .commons .api .LnEditor ;
13
14
import org .lfenergy .compas .sct .commons .domain .*;
14
15
import org .lfenergy .compas .sct .commons .dto .*;
15
16
import org .lfenergy .compas .sct .commons .exception .ScdException ;
16
- import org .lfenergy .compas .sct .commons .model .epf .EPF ;
17
- import org .lfenergy .compas .sct .commons .model .epf .TCBScopeType ;
18
- import org .lfenergy .compas .sct .commons .model .epf .TChannel ;
19
- import org .lfenergy .compas .sct .commons .model .epf .TChannelType ;
20
- import org .lfenergy .compas .sct .commons .model .epf .TChannelLevMod ;
17
+ import org .lfenergy .compas .sct .commons .model .epf .*;
21
18
import org .lfenergy .compas .sct .commons .scl .SclRootAdapter ;
22
19
import org .lfenergy .compas .sct .commons .scl .ied .IEDAdapter ;
23
20
import org .lfenergy .compas .sct .commons .scl .ldevice .LDeviceAdapter ;
@@ -65,9 +62,9 @@ public class ExtRefEditorService implements ExtRefEditor {
65
62
* 4. Active LNode source object that should match the provided parameters<br/>
66
63
* 5. Valid DataTypeTemplate Object hierarchy that should match the DO/DA/BDA parameters<br/>
67
64
*
68
- * @param scl SCL object
69
- * @param compasBay TCompasBay represent Bay Private
70
- * @param channel TChannel represent parameters
65
+ * @param scl SCL object
66
+ * @param compasBay TCompasBay represent Bay Private
67
+ * @param channel TChannel represent parameters
71
68
* @return the IED sources matching the LDEPF parameters
72
69
*/
73
70
private List <TIED > getIedSources (SCL scl , TCompasBay compasBay , TChannel channel ) {
@@ -77,8 +74,8 @@ private List<TIED> getIedSources(SCL scl, TCompasBay compasBay, TChannel channel
77
74
Optional <TCompasBay > tCompasBay = PrivateUtils .extractCompasPrivate (tied , TCompasBay .class );
78
75
return (channel .getBayScope ().equals (TCBScopeType .BAY_EXTERNAL )
79
76
&& tCompasBay .stream ().noneMatch (bay -> bay .getUUID ().equals (compasBay .getUUID ())))
80
- || (channel .getBayScope ().equals (TCBScopeType .BAY_INTERNAL )
81
- && tCompasBay .stream ().anyMatch (bay -> bay .getUUID ().equals (compasBay .getUUID ())));
77
+ || (channel .getBayScope ().equals (TCBScopeType .BAY_INTERNAL )
78
+ && tCompasBay .stream ().anyMatch (bay -> bay .getUUID ().equals (compasBay .getUUID ())));
82
79
}).filter (tied -> doesIcdHeaderMatchLDEPFChannel (tied , channel ))
83
80
.filter (tied -> ldeviceService .findLdevice (tied , channel .getLDInst ())
84
81
.filter (tlDevice -> PrivateUtils .extractStringPrivate (tlDevice .getLN0 (), COMPAS_LNODE_STATUS ).map (status -> status .equals (ActiveStatus .ON .getValue ())).orElse (false ))
@@ -121,36 +118,36 @@ private List<ExtRefInfo.ExtRefWithBayReference> getExtRefWithBayReferenceInLDEPF
121
118
*/
122
119
private static Boolean doesExtRefMatchLDEPFChannel (TExtRef extRef , TChannel tChannel ) {
123
120
Boolean doesExtRefDescMatchAnalogChannel = tChannel .getChannelType ().equals (TChannelType .ANALOG )
124
- && extRef .getDesc ().startsWith ("DYN_LDEPF_ANALOG CHANNEL " + tChannel .getChannelNum () + "_1_AnalogueValue" )
125
- && extRef .getDesc ().endsWith ("_" + tChannel .getDAName () + "_1" );
121
+ && extRef .getDesc ().startsWith ("DYN_LDEPF_ANALOG CHANNEL " + tChannel .getChannelNum () + "_1_AnalogueValue" )
122
+ && extRef .getDesc ().endsWith ("_" + tChannel .getDAName () + "_1" );
126
123
Boolean doesExtRefDescMatchDigitalChannel = tChannel .getChannelType ().equals (TChannelType .DIGITAL )
127
- && extRef .getDesc ().startsWith ("DYN_LDEPF_DIGITAL CHANNEL " + tChannel .getChannelNum () + "_1_BOOLEAN" )
128
- && extRef .getDesc ().endsWith ("_" + tChannel .getDAName () + "_1" );
124
+ && extRef .getDesc ().startsWith ("DYN_LDEPF_DIGITAL CHANNEL " + tChannel .getChannelNum () + "_1_BOOLEAN" )
125
+ && extRef .getDesc ().endsWith ("_" + tChannel .getDAName () + "_1" );
129
126
return extRef .isSetDesc () && (doesExtRefDescMatchAnalogChannel || doesExtRefDescMatchDigitalChannel )
130
- && extRef .isSetPLN () && Utils .lnClassEquals (extRef .getPLN (), tChannel .getLNClass ())
131
- && extRef .isSetPDO () && extRef .getPDO ().equals (tChannel .getDOName ());
127
+ && extRef .isSetPLN () && Utils .lnClassEquals (extRef .getPLN (), tChannel .getLNClass ())
128
+ && extRef .isSetPDO () && extRef .getPDO ().equals (tChannel .getDOName ());
132
129
}
133
130
134
131
/**
135
132
* Verify whether the IED satisfies the EPF channel for the private element `TCompasICDHeader`
136
133
*
137
- * @param tied TIED
138
- * @param channel TChannel
134
+ * @param tied TIED
135
+ * @param channel TChannel
139
136
* @return true if the TCompasICDHeader matches the EPF channel
140
137
*/
141
138
private static boolean doesIcdHeaderMatchLDEPFChannel (TIED tied , TChannel channel ) {
142
139
Optional <TCompasICDHeader > tCompasICDHeader = PrivateUtils .extractCompasPrivate (tied , TCompasICDHeader .class );
143
140
return tCompasICDHeader .map (compasICDHeader -> compasICDHeader .getIEDType ().value ().equals (channel .getIEDType ())
144
- && compasICDHeader .getIEDredundancy ().value ().equals (channel .getIEDRedundancy ().value ())
145
- && compasICDHeader .getIEDSystemVersioninstance ().toString ().equals (channel .getIEDSystemVersionInstance ()))
141
+ && compasICDHeader .getIEDredundancy ().value ().equals (channel .getIEDRedundancy ().value ())
142
+ && compasICDHeader .getIEDSystemVersioninstance ().toString ().equals (channel .getIEDSystemVersionInstance ()))
146
143
.orElse (false );
147
144
}
148
145
149
146
/**
150
147
* Provides Active LN Object that satisfies the EPF channel attributes (lnClass, lnInst, prefix)
151
148
*
152
149
* @param tlDevice TLDevice
153
- * @param channel TChannel
150
+ * @param channel TChannel
154
151
* @return AnyLN object that matches the EPF channel
155
152
*/
156
153
private Optional <TAnyLN > getActiveLNSourceByLDEPFChannel (TLDevice tlDevice , TChannel channel ) {
@@ -163,9 +160,9 @@ private Optional<TAnyLN> getActiveLNSourceByLDEPFChannel(TLDevice tlDevice, TCha
163
160
/**
164
161
* Verify whether the LN satisfies the EPF channel parameters for Data Type Template elements.
165
162
*
166
- * @param dtt TDataTypeTemplates
167
- * @param tAnyLN TAnyLN
168
- * @param channel TChannel
163
+ * @param dtt TDataTypeTemplates
164
+ * @param tAnyLN TAnyLN
165
+ * @param channel TChannel
169
166
* @return true if the LN matches the EPF channel
170
167
*/
171
168
private boolean isValidDataTypeTemplate (TDataTypeTemplates dtt , TAnyLN tAnyLN , TChannel channel ) {
@@ -185,7 +182,7 @@ private boolean isValidDataTypeTemplate(TDataTypeTemplates dtt, TAnyLN tAnyLN, T
185
182
if (isNotBlank (channel .getSBDAName ())) {
186
183
bdaNames .add (channel .getSBDAName ());
187
184
}
188
- return dataTypeTemplatesService .findDoLinkedToDa (dtt , tAnyLN .getLnType (), new DoLinkedToDaFilter (doName , sdoNames , daName , bdaNames )).isPresent ();
185
+ return dataTypeTemplatesService .findDoLinkedToDa (dtt , tAnyLN .getLnType (), new DoLinkedToDaFilter (doName , sdoNames , daName , bdaNames )).isPresent ();
189
186
}
190
187
191
188
@ Override
@@ -265,8 +262,8 @@ public List<SclReportItem> manageBindingForLDEPF(SCL scd, EPF epf) {
265
262
} else {
266
263
if (iedSources .size () > 1 ) {
267
264
errorHandler .get ().add (SclReportItem .warning (null , "There is more than one IED source to bind the signal " +
268
- "/IED@name=" + extRefBayRef .iedName () + "/LDevice@inst=LDEPF/LN0" +
269
- "/ExtRef@desc=" + extRefBayRef .extRef ().getDesc ()));
265
+ "/IED@name=" + extRefBayRef .iedName () + "/LDevice@inst=LDEPF/LN0" +
266
+ "/ExtRef@desc=" + extRefBayRef .extRef ().getDesc ()));
270
267
}
271
268
}
272
269
}))));
@@ -291,19 +288,19 @@ public void epfPostProcessing(SCL scd) {
291
288
Optional <TDAI > purPoseDAI = lnEditor .getDOAndDAInstances (ln0 , doLinkedPurPose );
292
289
293
290
boolean isSetSrcRefExistAndEmpty = setSrcRefDAI .isPresent ()
294
- && (!setSrcRefDAI .get ().isSetVal ()
295
- || (setSrcRefDAI .get ().isSetVal ()
296
- && setSrcRefDAI .get ().getVal ().getFirst ().getValue ().isEmpty ()));
291
+ && (!setSrcRefDAI .get ().isSetVal ()
292
+ || (setSrcRefDAI .get ().isSetVal ()
293
+ && setSrcRefDAI .get ().getVal ().getFirst ().getValue ().isEmpty ()));
297
294
boolean isPurposeExistAndMatchChannel = purPoseDAI .isPresent ()
298
- && purPoseDAI .get ().isSetVal ()
299
- && (purPoseDAI .get ().getVal ().getFirst ().getValue ().startsWith ("DYN_LDEPF_DIGITAL CHANNEL" )
300
- || purPoseDAI .get ().getVal ().getFirst ().getValue ().startsWith ("DYN_LDEPF_ANALOG CHANNEL" ));
301
- if (isSetSrcRefExistAndEmpty && isPurposeExistAndMatchChannel ) {
295
+ && purPoseDAI .get ().isSetVal ()
296
+ && (purPoseDAI .get ().getVal ().getFirst ().getValue ().startsWith ("DYN_LDEPF_DIGITAL CHANNEL" )
297
+ || purPoseDAI .get ().getVal ().getFirst ().getValue ().startsWith ("DYN_LDEPF_ANALOG CHANNEL" ));
298
+ if (isSetSrcRefExistAndEmpty && isPurposeExistAndMatchChannel ) {
302
299
DataObject dataObject = new DataObject ();
303
300
dataObject .setDoName (tdoi .getName ());
304
301
DataAttribute dataAttribute = new DataAttribute ();
305
302
dataAttribute .setDaName (SETSRCREF_DA_NAME );
306
- dataAttribute .setDaiValues (List .of (new DaVal (null , ldepfLdevice .getLdName ()+ "/" + LPHD0_PROXY )));
303
+ dataAttribute .setDaiValues (List .of (new DaVal (null , ldepfLdevice .getLdName () + "/" + LPHD0_PROXY )));
307
304
DoLinkedToDa doLinkedToDa = new DoLinkedToDa (dataObject , dataAttribute );
308
305
lnEditor .updateOrCreateDOAndDAInstances (ln0 , doLinkedToDa );
309
306
}
@@ -316,9 +313,7 @@ private void updateLDEPFExtRefBinding(ExtRefInfo.ExtRefWithBayReference extRefWi
316
313
tExtRef .setLdInst (setting .getLDInst ());
317
314
tExtRef .getLnClass ().add (setting .getLNClass ());
318
315
tExtRef .setLnInst (setting .getLNInst ());
319
- if (!isBlank (setting .getLNPrefix ())) {
320
- tExtRef .setPrefix (setting .getLNPrefix ());
321
- }
316
+ tExtRef .setPrefix (StringUtils .trimToNull (setting .getLNPrefix ()));
322
317
String doName = isBlank (setting .getDOInst ()) || setting .getDOInst ().equals ("0" ) ? setting .getDOName () : setting .getDOName () + setting .getDOInst ();
323
318
tExtRef .setDoName (doName );
324
319
// This is true for External Binding
@@ -334,31 +329,31 @@ private void updateLDEPFExtRefBinding(ExtRefInfo.ExtRefWithBayReference extRefWi
334
329
private String computeDaiValue (String lnPrefix , TExtRef extRef , String daName ) {
335
330
if (LN_PREFIX_B .equals (lnPrefix ) || LN_PREFIX_A .equals (lnPrefix )) {
336
331
return extRef .getIedName () +
337
- extRef .getLdInst () + "/" +
338
- trimToEmpty (extRef .getPrefix ()) +
339
- extRef .getLnClass ().getFirst () +
340
- trimToEmpty (extRef .getLnInst ()) + "." +
341
- extRef .getDoName () + "." + Q_DA_NAME ;
332
+ extRef .getLdInst () + "/" +
333
+ trimToEmpty (extRef .getPrefix ()) +
334
+ extRef .getLnClass ().getFirst () +
335
+ trimToEmpty (extRef .getLnInst ()) + "." +
336
+ extRef .getDoName () + "." + Q_DA_NAME ;
342
337
} else {
343
338
return extRef .getIedName () +
344
- extRef .getLdInst () + "/" +
345
- trimToEmpty (extRef .getPrefix ()) +
346
- extRef .getLnClass ().getFirst () +
347
- trimToEmpty (extRef .getLnInst ()) + "." +
348
- extRef .getDoName () + "." +
349
- daName ;
339
+ extRef .getLdInst () + "/" +
340
+ trimToEmpty (extRef .getPrefix ()) +
341
+ extRef .getLnClass ().getFirst () +
342
+ trimToEmpty (extRef .getLnInst ()) + "." +
343
+ extRef .getDoName () + "." +
344
+ daName ;
350
345
}
351
346
}
352
347
353
- private void updateLDEPFDos (TDataTypeTemplates dtt , TIED tied , TLDevice tlDevice , TExtRef tExtRef , TChannel setting ) {
354
- // Digital
348
+ private void updateLDEPFDos (TDataTypeTemplates dtt , TIED tied , TLDevice tlDevice , TExtRef tExtRef , TChannel setting ) {
349
+ // Digital
355
350
if (setting .getChannelType ().equals (TChannelType .DIGITAL )) {
356
351
lnEditor .findLn (tlDevice , tAnyLN -> lnEditor .matchesLn (tAnyLN , LN_RBDR , setting .getChannelNum (), null ))
357
352
.ifPresent (tln -> updateDaiValue (dtt , tied , tlDevice , tln , tExtRef , setting ));
358
353
lnEditor .findLn (tlDevice , tAnyLN -> lnEditor .matchesLn (tAnyLN , LN_RBDR , setting .getChannelNum (), LN_PREFIX_B ))
359
354
.ifPresent (tln -> updateDaiValue (dtt , tied , tlDevice , tln , tExtRef , setting ));
360
355
}
361
- // Analog
356
+ // Analog
362
357
if (setting .getChannelType ().equals (TChannelType .ANALOG )) {
363
358
lnEditor .findLn (tlDevice , tAnyLN -> lnEditor .matchesLn (tAnyLN , LN_RADR , setting .getChannelNum (), null ))
364
359
.ifPresent (tln -> updateDaiValue (dtt , tied , tlDevice , tln , tExtRef , setting ));
@@ -374,12 +369,12 @@ private void updateDaiValue(TDataTypeTemplates dtt, TIED tied, TLDevice tlDevice
374
369
375
370
private String getNewDaiValue (String daName , String lnPrefix , TExtRef extRef , TChannel setting ) {
376
371
return switch (daName ) {
377
- case DU_DA_NAME -> setting .isSetChannelShortLabel () ? setting .getChannelShortLabel (): null ;
372
+ case DU_DA_NAME -> setting .isSetChannelShortLabel () ? setting .getChannelShortLabel () : null ;
378
373
case SETVAL_DA_NAME -> {
379
- if (LN_PREFIX_B .equals (lnPrefix ) || LN_PREFIX_A .equals (lnPrefix )){
380
- yield setting .isSetChannelLevModQ () && !setting .getChannelLevModQ ().equals (TChannelLevMod .NA ) ? setting .getChannelLevModQ ().value (): null ;
374
+ if (LN_PREFIX_B .equals (lnPrefix ) || LN_PREFIX_A .equals (lnPrefix )) {
375
+ yield setting .isSetChannelLevModQ () && !setting .getChannelLevModQ ().equals (TChannelLevMod .NA ) ? setting .getChannelLevModQ ().value () : null ;
381
376
} else {
382
- yield setting .isSetChannelLevMod () && !setting .getChannelLevMod ().equals (TChannelLevMod .NA ) ? setting .getChannelLevMod ().value (): null ;
377
+ yield setting .isSetChannelLevMod () && !setting .getChannelLevMod ().equals (TChannelLevMod .NA ) ? setting .getChannelLevMod ().value () : null ;
383
378
}
384
379
}
385
380
case STVAL_DA_NAME -> ActiveStatus .ON .getValue ();
@@ -393,7 +388,7 @@ private void updateDaiVal(TDataTypeTemplates dtt, TIED tied, TLDevice tlDevice,
393
388
.map (doLinkedToDa1 -> lnEditor .getDoLinkedToDaCompletedFromDAI (tied , tlDevice .getInst (), tln , doLinkedToDa1 ))
394
389
.findFirst ()
395
390
.filter (doLinkedToDa1 -> {
396
- if (!doLinkedToDa1 .isUpdatable ()){
391
+ if (!doLinkedToDa1 .isUpdatable ()) {
397
392
errorHandler .get ().add (SclReportItem .warning (tied .getName () + "/" + LDEVICE_LDSUIED + "/" + LnId .from (tln ).lnClass () + "/DOI@name=\" " + doLinkedToDaFilter .doName () + "\" /DAI@name=\" " + doLinkedToDaFilter .daName () + "\" /Val" , "The DAI cannot be updated" ));
398
393
}
399
394
return doLinkedToDa1 .isUpdatable ();
0 commit comments