Skip to content

Commit d44ead5

Browse files
Merge pull request #497 from com-pas/develop
Release 0.2.41
2 parents 80b5b28 + 562662a commit d44ead5

File tree

7 files changed

+466
-86
lines changed

7 files changed

+466
-86
lines changed

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/SclService.java

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
package org.lfenergy.compas.sct.commons;
66

7-
import jakarta.xml.bind.JAXBContext;
87
import lombok.Getter;
98
import lombok.NonNull;
109
import lombok.RequiredArgsConstructor;
@@ -38,6 +37,7 @@
3837

3938
import static org.lfenergy.compas.sct.commons.util.CommonConstants.*;
4039
import static org.lfenergy.compas.sct.commons.util.PrivateEnum.COMPAS_ICDHEADER;
40+
import static org.lfenergy.compas.sct.commons.util.Utils.copyLn;
4141

4242
@Slf4j
4343
@RequiredArgsConstructor
@@ -224,21 +224,24 @@ public List<SclReportItem> manageMonitoringLns(SCL scd) {
224224
errorHanlder.clear();
225225
iedService.getFilteredIeds(scd, ied -> !ied.getName().contains(IED_TEST_NAME))
226226
.forEach(tied -> {
227-
Map<TServiceType, List<TExtRef>> serviceTypeToExtRefs = ldeviceService.getLdevices(tied)
227+
Map<TServiceType, List<IedSource>> serviceTypeToIedSource = ldeviceService.getLdevices(tied)
228228
.flatMap(tlDevice -> extRefReaderService.getExtRefs(tlDevice.getLN0()))
229229
.filter(tExtRef -> tExtRef.isSetServiceType() && tExtRef.isSetSrcCBName() && (tExtRef.getServiceType().equals(TServiceType.GOOSE) || tExtRef.getServiceType().equals(TServiceType.SMV)))
230-
.collect(Collectors.groupingBy(TExtRef::getServiceType));
230+
.collect(Collectors.groupingBy(tExtRef -> new IedSource(tExtRef.getIedName(), tExtRef.getSrcCBName(), tExtRef.getSrcLDInst(), tExtRef.getServiceType())))
231+
.keySet()
232+
.stream()
233+
.collect(Collectors.groupingBy(IedSource::serviceType));
231234
ldeviceService.findLdevice(tied, LDEVICE_LDSUIED).ifPresent(ldSUIEDLDevice -> {
232-
Optional.ofNullable(serviceTypeToExtRefs.get(TServiceType.GOOSE))
233-
.ifPresent(extRefs -> manageMonitoringLns(extRefs, scd, tied, ldSUIEDLDevice, DO_GOCBREF, MonitoringLnClassEnum.LGOS));
234-
Optional.ofNullable(serviceTypeToExtRefs.get(TServiceType.SMV))
235-
.ifPresent(extRefs -> manageMonitoringLns(extRefs, scd, tied, ldSUIEDLDevice, DO_SVCBREF, MonitoringLnClassEnum.LSVS));
235+
Optional.ofNullable(serviceTypeToIedSource.get(TServiceType.GOOSE))
236+
.ifPresent(iedSourceKeys -> manageMonitoringLns(iedSourceKeys, scd, tied, ldSUIEDLDevice, DO_GOCBREF, MonitoringLnClassEnum.LGOS));
237+
Optional.ofNullable(serviceTypeToIedSource.get(TServiceType.SMV))
238+
.ifPresent(iedSourceKeys -> manageMonitoringLns(iedSourceKeys, scd, tied, ldSUIEDLDevice, DO_SVCBREF, MonitoringLnClassEnum.LSVS));
236239
});
237240
});
238241
return errorHanlder;
239242
}
240243

241-
private void manageMonitoringLns(List<TExtRef> tExtRefs, SCL scd, TIED tied, TLDevice ldsuiedLdevice, String doName, MonitoringLnClassEnum monitoringLnClassEnum) {
244+
private void manageMonitoringLns(List<IedSource> iedSources, SCL scd, TIED tied, TLDevice ldsuiedLdevice, String doName, MonitoringLnClassEnum monitoringLnClassEnum) {
242245
List<TLN> lgosOrLsvsLns = lnService.getFilteredLns(ldsuiedLdevice, tln -> monitoringLnClassEnum.value().equals(tln.getLnClass().getFirst())).toList();
243246
if (lgosOrLsvsLns.isEmpty())
244247
errorHanlder.add(SclReportItem.warning(tied.getName() + "/" + LDEVICE_LDSUIED + "/" + monitoringLnClassEnum.value(), "There is no LN %s present in LDevice".formatted(monitoringLnClassEnum.value())));
@@ -252,43 +255,24 @@ private void manageMonitoringLns(List<TExtRef> tExtRefs, SCL scd, TIED tied, TLD
252255
return doLinkedToDa.isUpdatable();
253256
})
254257
.ifPresent(doLinkedToDa -> {
255-
log.info("Processing %d ExtRefs in LDName=%s of service type %s for LN (lnClass=%s, inst=%s, prefix=%s)".formatted(tExtRefs.size(), ldsuiedLdevice.getLdName(), monitoringLnClassEnum.value(), lgosOrLsvs.getLnClass().getFirst(), lgosOrLsvs.getInst(), lgosOrLsvs.getPrefix()));
256-
for (int i = 0; i < tExtRefs.size(); i++) {
258+
log.info("Processing %d IED Source in LDName=%s for LN (lnClass=%s, inst=%s, prefix=%s)".formatted(iedSources.size(), ldsuiedLdevice.getLdName(), lgosOrLsvs.getLnClass().getFirst(), lgosOrLsvs.getInst(), lgosOrLsvs.getPrefix()));
259+
for (int i = 0; i < iedSources.size(); i++) {
257260
TLN lnToAdd = copyLn(lgosOrLsvs); //duplicate actual LGOS or LSVS in order to add LDSUIED with extRefs properties
258-
TExtRef tExtRef = tExtRefs.get(i);
259-
TIED sourceIed = iedService.findByName(scd, tExtRef.getIedName()).orElseThrow(() -> new ScdException("IED.name '" + tExtRef.getIedName() + "' not found in SCD"));
260-
String sourceLdName = ldeviceService.findLdevice(sourceIed, tExtRef.getSrcLDInst()).orElseThrow(() -> new ScdException(String.format("LDevice.inst '%s' not found in IED '%s'", tExtRef.getSrcLDInst(), tExtRef.getIedName()))).getLdName();
261-
String lnClass = !tExtRef.isSetSrcLNClass() ? TLLN0Enum.LLN_0.value() : tExtRef.getSrcLNClass().getFirst();
261+
IedSource iedSource = iedSources.get(i);
262+
TIED sourceIed = iedService.findByName(scd, iedSource.iedName()).orElseThrow(() -> new ScdException("IED.name '" + iedSource.iedName() + "' not found in SCD"));
263+
String sourceLdName = ldeviceService.findLdevice(sourceIed, iedSource.srcLdInst()).orElseThrow(() -> new ScdException(String.format("LDevice.inst '%s' not found in IED '%s'", iedSource.srcLdInst(), iedSource.iedName()))).getLdName();
262264
lnToAdd.setInst(String.valueOf(i + 1));
263-
DaVal newVal = new DaVal(null, sourceLdName + "/" + lnClass + "." + tExtRef.getSrcCBName());
265+
DaVal newVal = new DaVal(null, sourceLdName + "/" + TLLN0Enum.LLN_0.value() + "." + iedSource.srcCBName());
264266
doLinkedToDa.dataAttribute().getDaiValues().clear();
265267
doLinkedToDa.dataAttribute().getDaiValues().add(newVal);
266268
lnService.updateOrCreateDOAndDAInstances(lnToAdd, doLinkedToDa);
267-
log.info("Processing %d ExtRefs in LDName=%s - added LN (lnClass=%s, inst=%s, prefix=%s) - update DOI(name=%s)/DAI(name=%s) with value=%s".formatted(tExtRefs.size(), ldsuiedLdevice.getLdName(), lgosOrLsvs.getLnClass().getFirst(), String.valueOf(i + 1), lgosOrLsvs.getPrefix(), doName, DA_SETSRCREF, newVal.val()));
269+
log.info("Processing %d IED Source in LDName=%s - added LN (lnClass=%s, inst=%s, prefix=%s) - update DOI(name=%s)/DAI(name=%s) with value=%s".formatted(iedSources.size(), ldsuiedLdevice.getLdName(), lgosOrLsvs.getLnClass().getFirst(), String.valueOf(i + 1), lgosOrLsvs.getPrefix(), doName, DA_SETSRCREF, newVal.val()));
268270
ldsuiedLdevice.getLN().add(lnToAdd);
269271
}
270272
ldsuiedLdevice.getLN().remove(lgosOrLsvs); //We can remove this LGOS or LSVS as we already added new ones
271273
}));
272274
}
273275

274-
private TLN copyLn(TLN tln) {
275-
TLN newLn = new TLN();
276-
newLn.getLnClass().addAll(tln.getLnClass());
277-
newLn.setInst(tln.getInst());
278-
newLn.setLnType(tln.getLnType());
279-
newLn.setPrefix(tln.getPrefix());
280-
newLn.setDesc(tln.getDesc());
281-
newLn.setInputs(tln.getInputs());
282-
newLn.setText(tln.getText());
283-
newLn.getPrivate().addAll(tln.getPrivate());
284-
newLn.getDataSet().addAll(tln.getDataSet());
285-
newLn.getAny().addAll(tln.getAny());
286-
newLn.getDOI().addAll(tln.getDOI());
287-
newLn.getLog().addAll(tln.getLog());
288-
newLn.getLogControl().addAll(tln.getLogControl());
289-
newLn.getOtherAttributes().putAll(tln.getOtherAttributes());
290-
newLn.getReportControl().addAll(tln.getReportControl());
291-
return newLn;
292-
}
276+
record IedSource(String iedName, String srcCBName, String srcLdInst, TServiceType serviceType){}
293277

294278
}

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/util/Utils.java

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import jakarta.xml.bind.*;
88
import jakarta.xml.bind.util.JAXBSource;
99
import org.apache.commons.lang3.StringUtils;
10-
import org.lfenergy.compas.scl2007b4.model.TP;
10+
import org.lfenergy.compas.scl2007b4.model.*;
1111
import org.lfenergy.compas.sct.commons.exception.ScdException;
1212

1313
import javax.xml.namespace.QName;
@@ -334,4 +334,118 @@ public static <T> T copySclElement(T object, Class<T> clazz) {
334334
public static Optional<String> extractFromP(String type, List<TP> listOfP) {
335335
return listOfP.stream().filter(tp -> type.equals(tp.getType())).map(TP::getValue).findFirst();
336336
}
337+
338+
public static TLN copyLn(TLN tln) {
339+
TLN newLn = new TLN();
340+
newLn.getLnClass().addAll(tln.getLnClass());
341+
newLn.setInst(tln.getInst());
342+
newLn.setLnType(tln.getLnType());
343+
newLn.setPrefix(tln.getPrefix());
344+
newLn.setDesc(tln.getDesc());
345+
newLn.setInputs(tln.getInputs());
346+
newLn.setText(tln.getText());
347+
newLn.getPrivate().addAll(tln.getPrivate());
348+
newLn.getDataSet().addAll(tln.getDataSet());
349+
newLn.getAny().addAll(tln.getAny());
350+
newLn.getDOI().addAll(tln.getDOI().stream().map(Utils::createDOI).toList());
351+
newLn.getLog().addAll(tln.getLog());
352+
newLn.getLogControl().addAll(tln.getLogControl());
353+
newLn.getOtherAttributes().putAll(tln.getOtherAttributes());
354+
newLn.getReportControl().addAll(tln.getReportControl());
355+
return newLn;
356+
}
357+
358+
private static TDOI createDOI(TDOI tdoi){
359+
TDOI newDOI = new TDOI();
360+
newDOI.setName(tdoi.getName());
361+
if(tdoi.isSetIx()){
362+
newDOI.setIx(tdoi.getIx());
363+
}
364+
if(tdoi.isSetSDIOrDAI()){
365+
newDOI.getSDIOrDAI().addAll((tdoi.getSDIOrDAI().stream().map(Utils::createSDIOrDAI).toList()));
366+
}
367+
if(tdoi.isSetPrivate()){
368+
newDOI.getPrivate().addAll(tdoi.getPrivate());
369+
}
370+
if(tdoi.isSetAny()){
371+
newDOI.getAny().addAll(tdoi.getAny());
372+
}
373+
updateUnNaming(newDOI, tdoi);
374+
return newDOI;
375+
}
376+
377+
private static TUnNaming createSDIOrDAI(TUnNaming tUnNaming){
378+
return switch (tUnNaming) {
379+
case TDAI tdai -> createDAI(tdai);
380+
case TSDI tsdi -> createSDI(tsdi);
381+
default -> throw new IllegalStateException("Unexpected value: " + tUnNaming);
382+
};
383+
}
384+
385+
private static TDAI createDAI(TDAI tdai){
386+
TDAI newDAI = new TDAI();
387+
newDAI.setName(tdai.getName());
388+
if(tdai.isSetVal()){
389+
newDAI.getVal().addAll((tdai.getVal().stream().map(tVal -> {
390+
TVal newVal = new TVal();
391+
newVal.setValue(tVal.getValue());
392+
if(tVal.isSetSGroup()){
393+
newVal.setSGroup(tVal.getSGroup());
394+
}
395+
return newVal;
396+
}).toList()));
397+
}
398+
if(tdai.isSetIx()){
399+
newDAI.setIx(tdai.getIx());
400+
}
401+
if(tdai.isSetSAddr()){
402+
newDAI.setSAddr(tdai.getSAddr());
403+
}
404+
if(tdai.isSetValImport()){
405+
newDAI.setValImport(tdai.isValImport());
406+
}
407+
if(tdai.isSetValKind()){
408+
newDAI.setValKind(tdai.getValKind());
409+
}
410+
if(tdai.isSetPrivate()){
411+
newDAI.getPrivate().addAll(tdai.getPrivate());
412+
}
413+
if(tdai.isSetAny()){
414+
newDAI.getAny().addAll(tdai.getAny());
415+
}
416+
updateUnNaming(newDAI, tdai);
417+
return newDAI;
418+
}
419+
420+
private static TSDI createSDI(TSDI tsdi){
421+
TSDI newSDI = new TSDI();
422+
newSDI.setName(tsdi.getName());
423+
if(tsdi.isSetSDIOrDAI()){
424+
newSDI.getSDIOrDAI().addAll((tsdi.getSDIOrDAI().stream().map(Utils::createSDIOrDAI).toList()));
425+
}
426+
if(tsdi.isSetIx()){
427+
newSDI.setIx(tsdi.getIx());
428+
}
429+
if(tsdi.isSetSAddr()){
430+
newSDI.setSAddr(tsdi.getSAddr());
431+
}
432+
if(tsdi.isSetPrivate()){
433+
newSDI.getPrivate().addAll(tsdi.getPrivate());
434+
}
435+
if(tsdi.isSetAny()){
436+
newSDI.getAny().addAll(tsdi.getAny());
437+
}
438+
updateUnNaming(newSDI, tsdi);
439+
return newSDI;
440+
}
441+
442+
private static void updateUnNaming(TUnNaming unNaming, TUnNaming unNamingSource){
443+
if(unNamingSource.isSetText()){
444+
unNaming.setText(unNamingSource.getText());
445+
}
446+
if(unNamingSource.isSetDesc()){
447+
unNaming.setDesc(unNamingSource.getDesc());
448+
}
449+
}
450+
337451
}

0 commit comments

Comments
 (0)