1010import lombok .extern .slf4j .Slf4j ;
1111import org .lfenergy .compas .scl2007b4 .model .*;
1212import org .lfenergy .compas .sct .commons .api .SclEditor ;
13+ import org .lfenergy .compas .sct .commons .domain .DaVal ;
14+ import org .lfenergy .compas .sct .commons .domain .DoLinkedToDaFilter ;
1315import org .lfenergy .compas .sct .commons .dto .*;
1416import org .lfenergy .compas .sct .commons .exception .ScdException ;
15- import org .lfenergy .compas .sct .commons .scl .ExtRefService ;
1617import org .lfenergy .compas .sct .commons .scl .SclRootAdapter ;
1718import org .lfenergy .compas .sct .commons .scl .com .CommunicationAdapter ;
1819import org .lfenergy .compas .sct .commons .scl .com .ConnectedAPAdapter ;
2627import org .lfenergy .compas .sct .commons .scl .ldevice .LDeviceAdapter ;
2728import org .lfenergy .compas .sct .commons .scl .ln .AbstractLNAdapter ;
2829import org .lfenergy .compas .sct .commons .scl .ln .LN0Adapter ;
29- import org .lfenergy .compas .sct .commons .scl .ln .LNAdapter ;
3030import org .lfenergy .compas .sct .commons .util .MonitoringLnClassEnum ;
3131import org .lfenergy .compas .sct .commons .util .PrivateUtils ;
3232import org .lfenergy .compas .sct .commons .util .Utils ;
3333
3434import java .util .*;
3535
36- import static org .lfenergy .compas .sct .commons .util .CommonConstants .IED_TEST_NAME ;
36+ import static org .lfenergy .compas .sct .commons .util .CommonConstants .* ;
3737import static org .lfenergy .compas .sct .commons .util .PrivateEnum .COMPAS_ICDHEADER ;
3838import static org .lfenergy .compas .sct .commons .util .Utils .copySclElement ;
3939
@@ -217,14 +217,10 @@ public List<SclReportItem> updateDoInRef(SCL scd) {
217217 public List <SclReportItem > manageMonitoringLns (SCL scd ) {
218218 errorHanlder .clear ();
219219 iedService .getFilteredIeds (scd , ied -> !ied .getName ().contains (IED_TEST_NAME ))
220- .forEach (tied -> ldeviceService . findLdevice ( tied , tlDevice -> "LDSUIED" . equals ( tlDevice . getInst ()))
221- . filter ( tlDevice -> tlDevice . getLN0 (). isSetInputs ( ))
220+ .forEach (tied ->
221+ ldeviceService . findLdevice ( tied , tlDevice -> LDEVICE_LDSUIED . equals ( tlDevice . getInst () ))
222222 .ifPresent (tlDevice -> {
223- List <TExtRef > tExtRefs = new ExtRefService ().filterDuplicatedExtRefs (tlDevice .getLN0 ().getInputs ().getExtRef ())
224- .stream ()
225- .filter (TExtRef ::isSetServiceType )
226- .filter (TExtRef ::isSetSrcCBName )
227- .toList ();
223+ List <TExtRef > tExtRefs = new ExtRefReaderService ().getExtRefs (scd ).toList ();
228224 manageMonitoringLns (tExtRefs .stream ().filter (tExtRef -> TServiceType .GOOSE .equals (tExtRef .getServiceType ())).toList (), scd , tied , tlDevice , DO_GOCBREF , MonitoringLnClassEnum .LGOS );
229225 manageMonitoringLns (tExtRefs .stream ().filter (tExtRef -> TServiceType .SMV .equals (tExtRef .getServiceType ())).toList (), scd , tied , tlDevice , DO_SVCBREF , MonitoringLnClassEnum .LSVS );
230226 }));
@@ -235,32 +231,40 @@ private void manageMonitoringLns(List<TExtRef> tExtRefs, SCL scd, TIED tied, TLD
235231 List <TLN > tlns = lnService .getFilteredLns (tlDevice , tln -> monitoringLnClassEnum .value ().equals (tln .getLnClass ().getFirst ())).toList ();
236232 if (tlns .isEmpty ())
237233 errorHanlder .add (SclReportItem .warning (tied .getName ()+"/" +tlDevice .getInst ()+"/" +monitoringLnClassEnum .value (), "There is no LN %s present in LDevice" .formatted (monitoringLnClassEnum .value ())));
234+ if (tExtRefs .isEmpty ()) {
235+ return ;
236+ }
237+ DoLinkedToDaFilter doLinkedToDaFilter = new DoLinkedToDaFilter (doName , List .of (), DA_SETSRCREF , List .of ());
238+ DataTypeTemplatesService dataTypeTemplatesService = new DataTypeTemplatesService ();
238239
239- tlns .forEach (tln -> {
240- LNAdapter lnAdapter = new LNAdapter (new LDeviceAdapter (new IEDAdapter (new SclRootAdapter (scd ), tied ), tlDevice ), tln );
241- lnAdapter
242- .getDAI (new DataAttributeRef (tln , new DoTypeName (doName ), new DaTypeName (DA_SETSRCREF )), true )
243- .stream ()
244- .findFirst ()
245- .ifPresentOrElse (daToUpdateFilter -> {
246- removeLnsByLnClass (monitoringLnClassEnum , tlDevice );
247- for (int i = 0 ; i < tExtRefs .size (); i ++) {
248- TLN copiedLn = copySclElement (tln , TLN .class );
249- TExtRef tExtRef = tExtRefs .get (i );
250- TIED sourceIed = iedService .findByName (scd , tExtRef .getIedName ())
251- .orElseThrow (() -> new ScdException ("IED.name '" + tExtRef .getIedName () + "' not found in SCD" ));
252- String sourceLdName = ldeviceService .findLdevice (sourceIed , tExtRef .getSrcLDInst ())
253- .orElseThrow (() -> new ScdException (String .format ("LDevice.inst '%s' not found in IED '%s'" , tExtRef .getSrcLDInst (), tExtRef .getIedName ())))
254- .getLdName ();
255- String lnClass = !tExtRef .isSetSrcLNClass () ? TLLN0Enum .LLN_0 .value () : tExtRef .getSrcLNClass ().getFirst ();
256- lnAdapter .getCurrentElem ().setInst (String .valueOf (i + 1 ));
257- daToUpdateFilter .setVal (sourceLdName + "/" + lnClass + "." + tExtRef .getSrcCBName ());
258- lnAdapter .updateDAI (daToUpdateFilter );
259- tlDevice .getLN ().add (copiedLn );//value copy
260- }
261- }, () -> errorHanlder .add (SclReportItem .warning (lnAdapter .getXPath () + "/DOI@name=\" " + doName + "\" /DAI@name=\" setSrcRef\" /Val" ,
262- "The DAI cannot be updated" )));
263- });
240+ tlns .forEach (tln -> dataTypeTemplatesService .getFilteredDoLinkedToDa (scd .getDataTypeTemplates (), tln .getLnType (), doLinkedToDaFilter )
241+ .map (doLinkedToDa -> lnService .getDoLinkedToDaCompletedFromDAI (tied , tlDevice .getInst (), tln , doLinkedToDa ))
242+ .findFirst ()
243+ .ifPresent (doLinkedToDa -> {
244+ if (!doLinkedToDa .isUpdatable ()) {
245+ errorHanlder .add (SclReportItem .warning (tied .getName ()+"/" +tlDevice .getInst ()+"/" +monitoringLnClassEnum .value () + "/DOI@name=\" " + doName + "\" /DAI@name=\" setSrcRef\" /Val" , "The DAI cannot be updated" ));
246+ } else {
247+ TLN lnToUpdate = tln ;
248+ // Remove LN
249+ removeLnsByLnClass (monitoringLnClassEnum , tlDevice );
250+ for (int i = 0 ; i < tExtRefs .size (); i ++) {
251+ tlDevice .getLN ().add (lnToUpdate );
252+
253+ TExtRef tExtRef = tExtRefs .get (i );
254+ TIED sourceIed = iedService .findByName (scd , tExtRef .getIedName ())
255+ .orElseThrow (() -> new ScdException ("IED.name '" + tExtRef .getIedName () + "' not found in SCD" ));
256+ String sourceLdName = ldeviceService .findLdevice (sourceIed , tExtRef .getSrcLDInst ())
257+ .orElseThrow (() -> new ScdException (String .format ("LDevice.inst '%s' not found in IED '%s'" , tExtRef .getSrcLDInst (), tExtRef .getIedName ())))
258+ .getLdName ();
259+ String lnClass = !tExtRef .isSetSrcLNClass () ? TLLN0Enum .LLN_0 .value () : tExtRef .getSrcLNClass ().getFirst ();
260+ tln .setInst (String .valueOf (i + 1 ));
261+ doLinkedToDa .dataAttribute ().getDaiValues ().add (new DaVal (null , sourceLdName + "/" + lnClass + "." + tExtRef .getSrcCBName ()));
262+ lnService .updateOrCreateDOAndDAInstances (lnToUpdate , doLinkedToDa );
263+
264+ lnToUpdate = copySclElement (tln , TLN .class ); //value copy
265+ }
266+ }
267+ }));
264268 }
265269
266270 private void removeLnsByLnClass (MonitoringLnClassEnum monitoringLnClassEnum , TLDevice tlDevice ) {
0 commit comments