4
4
5
5
package org .lfenergy .compas .sct .commons ;
6
6
7
+ import lombok .Getter ;
7
8
import lombok .RequiredArgsConstructor ;
8
9
import org .lfenergy .compas .scl2007b4 .model .*;
9
10
import org .lfenergy .compas .sct .commons .api .ExtRefEditor ;
15
16
import org .lfenergy .compas .sct .commons .model .epf .TCBScopeType ;
16
17
import org .lfenergy .compas .sct .commons .model .epf .TChannel ;
17
18
import org .lfenergy .compas .sct .commons .model .epf .TChannelType ;
19
+ import org .lfenergy .compas .sct .commons .model .epf .TChannelLevMod ;
18
20
import org .lfenergy .compas .sct .commons .scl .SclRootAdapter ;
19
21
import org .lfenergy .compas .sct .commons .scl .ied .IEDAdapter ;
20
22
import org .lfenergy .compas .sct .commons .scl .ldevice .LDeviceAdapter ;
34
36
@ RequiredArgsConstructor
35
37
public class ExtRefEditorService implements ExtRefEditor {
36
38
private static final String INVALID_OR_MISSING_ATTRIBUTES_IN_EXT_REF_BINDING_INFO = "Invalid or missing attributes in ExtRef binding info" ;
39
+ private static final List <DoNameAndDaName > DO_DA_MAPPINGS = List .of (
40
+ new DoNameAndDaName (CHNUM1_DO_NAME , DU_DA_NAME ),
41
+ new DoNameAndDaName (LEVMOD_DO_NAME , SETVAL_DA_NAME ),
42
+ new DoNameAndDaName (MOD_DO_NAME , STVAL_DA_NAME ),
43
+ new DoNameAndDaName (SRCREF_DO_NAME , SETSRCREF_DA_NAME )
44
+ );
37
45
38
46
private final IedService iedService ;
39
47
private final LdeviceService ldeviceService ;
40
48
private final LnEditor lnEditor ;
41
49
private final DataTypeTemplatesService dataTypeTemplatesService ;
42
50
51
+ @ Getter
52
+ private final List <SclReportItem > errorHandler = new ArrayList <>();
53
+
43
54
/**
44
55
* Provides valid IED sources according to EPF configuration.<br/>
45
56
* EPF verification include:<br/>
@@ -76,17 +87,16 @@ private List<TIED> getIedSources(SclRootAdapter sclRootAdapter, TCompasBay compa
76
87
* - The location of ExtRef should be in LDevice (inst=LDEPF) <br/>
77
88
* - ExtRef that lacks Bay or ICDHeader Private is not returned <br/>
78
89
*
79
- * @param sclReportItems List of SclReportItem
80
90
* @return list of ExtRef and associated Bay
81
91
*/
82
- private List <ExtRefInfo .ExtRefWithBayReference > getExtRefWithBayReferenceInLDEPF (TDataTypeTemplates dataTypeTemplates , TIED tied , final TLDevice tlDevice , final List < SclReportItem > sclReportItems ) {
92
+ private List <ExtRefInfo .ExtRefWithBayReference > getExtRefWithBayReferenceInLDEPF (TDataTypeTemplates dataTypeTemplates , TIED tied , final TLDevice tlDevice ) {
83
93
List <ExtRefInfo .ExtRefWithBayReference > extRefBayReferenceList = new ArrayList <>();
84
94
String lDevicePath = "SCL/IED[@name=\" " + tied .getName () + "\" ]/AccessPoint/Server/LDevice[@inst=\" " + tlDevice .getInst () + "\" ]" ;
85
95
Optional <TCompasBay > tCompasBay = PrivateUtils .extractCompasPrivate (tied , TCompasBay .class );
86
96
if (tCompasBay .isEmpty ()) {
87
- sclReportItems .add (SclReportItem .error (lDevicePath , "The IED has no Private Bay" ));
97
+ errorHandler .add (SclReportItem .error (lDevicePath , "The IED has no Private Bay" ));
88
98
if (PrivateUtils .extractCompasPrivate (tied , TCompasICDHeader .class ).isEmpty ()) {
89
- sclReportItems .add (SclReportItem .error (lDevicePath , "The IED has no Private compas:ICDHeader" ));
99
+ errorHandler .add (SclReportItem .error (lDevicePath , "The IED has no Private compas:ICDHeader" ));
90
100
}
91
101
return Collections .emptyList ();
92
102
}
@@ -97,7 +107,7 @@ private List<ExtRefInfo.ExtRefWithBayReference> getExtRefWithBayReferenceInLDEPF
97
107
.getExtRef ().stream ()
98
108
.map (extRef -> new ExtRefInfo .ExtRefWithBayReference (tied .getName (), tCompasBay .get (), extRef )).toList ());
99
109
} else {
100
- sclReportItems .add (SclReportItem .error (lDevicePath , "DO@name=Mod/DA@name=stVal not found in DataTypeTemplate" ));
110
+ errorHandler .add (SclReportItem .error (lDevicePath , "DO@name=Mod/DA@name=stVal not found in DataTypeTemplate" ));
101
111
}
102
112
return extRefBayReferenceList ;
103
113
}
@@ -114,7 +124,7 @@ private static Boolean doesExtRefMatchLDEPFChannel(TExtRef extRef, TChannel tCha
114
124
&& extRef .getDesc ().startsWith ("DYN_LDEPF_ANALOG CHANNEL " + tChannel .getChannelNum () + "_1_AnalogueValue" )
115
125
&& extRef .getDesc ().endsWith ("_" + tChannel .getDAName () + "_1" );
116
126
Boolean doesExtRefDescMatchDigitalChannel = tChannel .getChannelType ().equals (TChannelType .DIGITAL )
117
- && extRef .getDesc ().startsWith ("DYN_LDEPF_DIGITAL CHANNEL " + tChannel .getChannelNum () + "_1_BOOLEEN " )
127
+ && extRef .getDesc ().startsWith ("DYN_LDEPF_DIGITAL CHANNEL " + tChannel .getChannelNum () + "_1_BOOLEAN " )
118
128
&& extRef .getDesc ().endsWith ("_" + tChannel .getDAName () + "_1" );
119
129
return extRef .isSetDesc () && (doesExtRefDescMatchAnalogChannel || doesExtRefDescMatchDigitalChannel )
120
130
&& extRef .isSetPLN () && Utils .lnClassEquals (extRef .getPLN (), tChannel .getLNClass ())
@@ -263,29 +273,29 @@ public TExtRef updateExtRefSource(SCL scd, ExtRefInfo extRefInfo) throws ScdExce
263
273
264
274
@ Override
265
275
public List <SclReportItem > manageBindingForLDEPF (SCL scd , EPF epf ) {
266
- List < SclReportItem > sclReportItems = new ArrayList <> ();
276
+ errorHandler . clear ();
267
277
SclRootAdapter sclRootAdapter = new SclRootAdapter (scd );
268
- if (!epf .isSetChannels ()) return sclReportItems ;
278
+ if (!epf .isSetChannels ()) return errorHandler ;
269
279
iedService .getFilteredIeds (scd , ied -> !ied .getName ().contains ("TEST" ))
270
280
.forEach (tied -> ldeviceService .findLdevice (tied , LDEVICE_LDEPF )
271
- .ifPresent (tlDevice -> getExtRefWithBayReferenceInLDEPF (scd .getDataTypeTemplates (), tied , tlDevice , sclReportItems )
281
+ .ifPresent (tlDevice -> getExtRefWithBayReferenceInLDEPF (scd .getDataTypeTemplates (), tied , tlDevice )
272
282
.forEach (extRefBayRef -> epf .getChannels ().getChannel ().stream ().filter (tChannel -> doesExtRefMatchLDEPFChannel (extRefBayRef .extRef (), tChannel ))
273
283
.findFirst ().ifPresent (channel -> {
274
284
List <TIED > iedSources = getIedSources (sclRootAdapter , extRefBayRef .compasBay (), channel );
275
285
if (iedSources .size () == 1 ) {
276
286
updateLDEPFExtRefBinding (extRefBayRef .extRef (), iedSources .getFirst (), channel );
277
287
LDeviceAdapter lDeviceAdapter = new LDeviceAdapter (new IEDAdapter (sclRootAdapter , tied .getName ()), tlDevice );
278
- sclReportItems . addAll ( updateLDEPFDos (lDeviceAdapter , extRefBayRef .extRef (), channel ) );
288
+ updateLDEPFDos (lDeviceAdapter , extRefBayRef .extRef (), channel );
279
289
} else {
280
290
if (iedSources .size () > 1 ) {
281
- sclReportItems .add (SclReportItem .warning (null , "There is more than one IED source to bind the signal " +
291
+ errorHandler .add (SclReportItem .warning (null , "There is more than one IED source to bind the signal " +
282
292
"/IED@name=" + extRefBayRef .iedName () + "/LDevice@inst=LDEPF/LN0" +
283
293
"/ExtRef@desc=" + extRefBayRef .extRef ().getDesc ()));
284
294
}
285
295
// If the source IED is not found, there will be no update or report message.
286
296
}
287
297
}))));
288
- return sclReportItems ;
298
+ return errorHandler ;
289
299
}
290
300
291
301
@ Override
@@ -332,44 +342,44 @@ private void updateLDEPFExtRefBinding(TExtRef extRef, TIED iedSource, TChannel s
332
342
extRef .setDoName (doName );
333
343
}
334
344
335
- private List <SclReportItem > updateLDEPFDos (LDeviceAdapter lDeviceAdapter , TExtRef extRef , TChannel setting ) {
336
- List <SclReportItem > sclReportItems = new ArrayList <>();
337
- List <DoNameAndDaName > doNameAndDaNameList = List .of (
338
- new DoNameAndDaName (CHNUM1_DO_NAME , DU_DA_NAME ),
339
- new DoNameAndDaName (LEVMOD_DO_NAME , SETVAL_DA_NAME ),
340
- new DoNameAndDaName (MOD_DO_NAME , STVAL_DA_NAME ),
341
- new DoNameAndDaName (SRCREF_DO_NAME , SETSRCREF_DA_NAME )
342
- );
345
+ private void updateLDEPFDos (LDeviceAdapter lDeviceAdapter , TExtRef extRef , TChannel setting ) {
343
346
if (setting .getChannelType ().equals (TChannelType .DIGITAL )) {
344
347
//digital
345
348
lDeviceAdapter .findLnAdapter (LN_RBDR , setting .getChannelNum (), null )
346
- .ifPresent (lnAdapter -> doNameAndDaNameList .forEach (doNameAndDaName -> updateVal (lnAdapter , doNameAndDaName . doName , doNameAndDaName . daName , extRef , setting ). ifPresent ( sclReportItems :: add )));
349
+ .ifPresent (lnAdapter -> DO_DA_MAPPINGS .forEach (doNameAndDaName -> updateVal (lnAdapter , doNameAndDaName , extRef , setting )));
347
350
lDeviceAdapter .findLnAdapter (LN_RBDR , setting .getChannelNum (), LN_PREFIX_B )
348
- .ifPresent (lnAdapter -> doNameAndDaNameList .forEach (doNameAndDaName -> updateVal (lnAdapter , doNameAndDaName . doName , doNameAndDaName . daName , extRef , setting ). ifPresent ( sclReportItems :: add )));
351
+ .ifPresent (lnAdapter -> DO_DA_MAPPINGS .forEach (doNameAndDaName -> updateVal (lnAdapter , doNameAndDaName , extRef , setting )));
349
352
}
350
353
if (setting .getChannelType ().equals (TChannelType .ANALOG )) {
351
354
//analog
352
355
lDeviceAdapter .findLnAdapter (LN_RADR , setting .getChannelNum (), null )
353
- .ifPresent (lnAdapter -> doNameAndDaNameList .forEach (doNameAndDaName -> updateVal (lnAdapter , doNameAndDaName . doName , doNameAndDaName . daName , extRef , setting ). ifPresent ( sclReportItems :: add )));
356
+ .ifPresent (lnAdapter -> DO_DA_MAPPINGS .forEach (doNameAndDaName -> updateVal (lnAdapter , doNameAndDaName , extRef , setting )));
354
357
lDeviceAdapter .findLnAdapter (LN_RADR , setting .getChannelNum (), LN_PREFIX_A )
355
- .ifPresent (lnAdapter -> doNameAndDaNameList .forEach (doNameAndDaName -> updateVal (lnAdapter , doNameAndDaName . doName , doNameAndDaName . daName , extRef , setting ). ifPresent ( sclReportItems :: add )));
358
+ .ifPresent (lnAdapter -> DO_DA_MAPPINGS .forEach (doNameAndDaName -> updateVal (lnAdapter , doNameAndDaName , extRef , setting )));
356
359
}
357
- return sclReportItems ;
358
360
}
359
361
360
- private Optional <SclReportItem > updateVal (AbstractLNAdapter <?> lnAdapter , String doName , String daName , TExtRef extRef , TChannel setting ) {
361
- String value = switch (daName ) {
362
- case DU_DA_NAME -> setting .getChannelShortLabel ();
363
- case SETVAL_DA_NAME -> LN_PREFIX_B .equals (lnAdapter .getPrefix ()) || LN_PREFIX_A .equals (lnAdapter .getPrefix ()) ? setting .getChannelLevModQ ().value () : setting .getChannelLevMod ().value ();
364
- case STVAL_DA_NAME -> ActiveStatus .ON .getValue ();
365
- case SETSRCREF_DA_NAME -> computeDaiValue (lnAdapter , extRef , setting .getDAName ());
366
- default -> null ;
362
+ private void updateVal (AbstractLNAdapter <?> lnAdapter , DoNameAndDaName doDaName , TExtRef extRef , TChannel setting ) {
363
+ String lnPrefix = lnAdapter .getPrefix ();
364
+ Optional <SclReportItem > sclReportItem = switch (doDaName .daName ) {
365
+ case DU_DA_NAME -> setting .isSetChannelShortLabel () ? lnAdapter .getDOIAdapterByName (doDaName .doName ).updateDAI (doDaName .daName , setting .getChannelShortLabel ()) :
366
+ Optional .empty ();
367
+ case SETVAL_DA_NAME -> {
368
+ if (LN_PREFIX_B .equals (lnPrefix ) || LN_PREFIX_A .equals (lnPrefix )) {
369
+ yield setting .isSetChannelLevModQ () && !setting .getChannelLevModQ ().equals (TChannelLevMod .NA ) ? lnAdapter .getDOIAdapterByName (doDaName .doName ).updateDAI (doDaName .daName , setting .getChannelLevModQ ().value ()) : Optional .empty ();
370
+ } else {
371
+ yield setting .isSetChannelLevMod () && !setting .getChannelLevMod ().equals (TChannelLevMod .NA ) ? lnAdapter .getDOIAdapterByName (doDaName .doName ).updateDAI (doDaName .daName , setting .getChannelLevMod ().value ()) : Optional .empty ();
372
+ }
373
+ }
374
+ case STVAL_DA_NAME -> lnAdapter .getDOIAdapterByName (doDaName .doName ).updateDAI (doDaName .daName , ActiveStatus .ON .getValue ());
375
+ case SETSRCREF_DA_NAME -> lnAdapter .getDOIAdapterByName (doDaName .doName ).updateDAI (doDaName .daName , computeDaiValue (lnPrefix , extRef , setting .getDAName ()));
376
+ default -> throw new IllegalStateException ("Unexpected value: " + doDaName .daName );
367
377
};
368
- return lnAdapter . getDOIAdapterByName ( doName ). updateDAI ( daName , value );
378
+ sclReportItem . ifPresent ( errorHandler :: add );
369
379
}
370
380
371
- private String computeDaiValue (AbstractLNAdapter <?> lnAdapter , TExtRef extRef , String daName ) {
372
- if (LN_PREFIX_B .equals (lnAdapter . getPrefix ()) || LN_PREFIX_A .equals (lnAdapter . getPrefix () )) {
381
+ private String computeDaiValue (String lnPrefix , TExtRef extRef , String daName ) {
382
+ if (LN_PREFIX_B .equals (lnPrefix ) || LN_PREFIX_A .equals (lnPrefix )) {
373
383
return extRef .getIedName () +
374
384
extRef .getLdInst () + "/" +
375
385
trimToEmpty (extRef .getPrefix ()) +
0 commit comments