Skip to content

Commit ebbac56

Browse files
Merge pull request #434 from com-pas/develop
Release 0.2.30
2 parents 00a334c + d47bf74 commit ebbac56

File tree

14 files changed

+138
-565
lines changed

14 files changed

+138
-565
lines changed

sct-app/src/test/java/org.lfenergy.compas.sct.app/SclAutomationServiceIntegrationTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
import org.junit.jupiter.api.Test;
99
import org.lfenergy.compas.scl2007b4.model.LN0;
1010
import org.lfenergy.compas.scl2007b4.model.SCL;
11-
import org.lfenergy.compas.sct.commons.ControlBlockEditorService;
12-
import org.lfenergy.compas.sct.commons.LdeviceService;
13-
import org.lfenergy.compas.sct.commons.SclService;
14-
import org.lfenergy.compas.sct.commons.SubstationService;
11+
import org.lfenergy.compas.sct.commons.*;
1512
import org.lfenergy.compas.sct.commons.api.ControlBlockEditor;
1613
import org.lfenergy.compas.sct.commons.api.SclEditor;
1714
import org.lfenergy.compas.sct.commons.api.SubstationEditor;
@@ -34,7 +31,7 @@ class SclAutomationServiceIntegrationTest {
3431

3532
private SclAutomationService sclAutomationService ;
3633
private static final SclEditor sclEditor = new SclService() ;
37-
private static final SubstationEditor substationEditor = new SubstationService() ;
34+
private static final SubstationEditor substationEditor = new SubstationService(new VoltageLevelService()) ;
3835
private static final ControlBlockEditor controlBlockEditor = new ControlBlockEditorService(new ControlService(), new LdeviceService()) ;
3936

4037
private HeaderDTO headerDTO;

sct-commons/pom.xml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -197,25 +197,6 @@
197197
<clearOutputDir>false</clearOutputDir>
198198
</configuration>
199199
</execution>
200-
<execution>
201-
<id>cb_po</id>
202-
<goals>
203-
<goal>xjc</goal>
204-
</goals>
205-
<configuration>
206-
<sources>
207-
<source>
208-
${project.basedir}/src/main/resources/xsd/CB_REPORT_SUPERVISION_Config_file.xsd
209-
</source>
210-
</sources>
211-
<xjbSources>
212-
<xjbSource>${project.basedir}/src/main/resources/binding_configuration.xjb</xjbSource>
213-
</xjbSources>
214-
<packageName>org.lfenergy.compas.sct.commons.model.cb_po</packageName>
215-
<noPackageLevelAnnotations>true</noPackageLevelAnnotations>
216-
<clearOutputDir>false</clearOutputDir>
217-
</configuration>
218-
</execution>
219200
<execution>
220201
<id>cbcom</id>
221202
<goals>

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
package org.lfenergy.compas.sct.commons;
66

77
import lombok.NonNull;
8+
import lombok.RequiredArgsConstructor;
89
import org.lfenergy.compas.scl2007b4.model.SCL;
910
import org.lfenergy.compas.scl2007b4.model.TBay;
1011
import org.lfenergy.compas.scl2007b4.model.TSubstation;
1112
import org.lfenergy.compas.scl2007b4.model.TVoltageLevel;
1213
import org.lfenergy.compas.sct.commons.api.SubstationEditor;
1314
import org.lfenergy.compas.sct.commons.exception.ScdException;
14-
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
15-
import org.lfenergy.compas.sct.commons.scl.sstation.SubstationAdapter;
16-
import org.lfenergy.compas.sct.commons.scl.sstation.VoltageLevelAdapter;
1715

16+
@RequiredArgsConstructor
1817
public class SubstationService implements SubstationEditor {
1918

19+
private final VoltageLevelService voltageLevelService;
20+
2021
@Override
2122
public void addSubstation(@NonNull SCL scd, @NonNull SCL ssd) throws ScdException {
2223
if (scd.getSubstation().size() > 1) {
@@ -25,53 +26,48 @@ public void addSubstation(@NonNull SCL scd, @NonNull SCL ssd) throws ScdExceptio
2526
if (ssd.getSubstation().size() != 1) {
2627
throw new ScdException(String.format("SSD file must have exactly 1 Substation, but got %d", ssd.getSubstation().size()));
2728
}
28-
TSubstation ssdTSubstation = ssd.getSubstation().get(0);
29+
TSubstation ssdTSubstation = ssd.getSubstation().getFirst();
2930
if (scd.getSubstation().isEmpty()) {
3031
scd.getSubstation().add(ssdTSubstation);
3132
} else {
32-
TSubstation scdTSubstation = scd.getSubstation().get(0);
33-
if (scdTSubstation.getName().equalsIgnoreCase(ssdTSubstation.getName())) {
34-
SubstationAdapter scdSubstationAdapter = new SclRootAdapter(scd).getSubstationAdapter(scdTSubstation.getName());
33+
TSubstation scdTSubstation = scd.getSubstation().getFirst();
34+
if (scdTSubstation.getName().equalsIgnoreCase(ssdTSubstation.getName())){
3535
for (TVoltageLevel tvl : ssdTSubstation.getVoltageLevel()) {
36-
updateVoltageLevel(scdSubstationAdapter, tvl);
36+
updateVoltageLevel(scd, tvl);
3737
}
38-
} else
38+
} else {
3939
throw new ScdException("SCD file must have only one Substation and the Substation name from SSD file is" +
4040
" different from the one in SCD file. The files are rejected.");
41+
}
4142
}
4243
}
4344

4445
/**
4546
* Creates new VoltageLevel section or updates VoltageLevel contents
46-
* @param scdSubstationAdapter Substation in which VoltageLevel should be created/updated
47+
* @param scd SCL contain Substation in which VoltageLevel should be created/updated
4748
* @param vl VoltageLevel to create/update
4849
* @throws ScdException throws when unable to create new VoltageLevel section which is not already present in Substation
4950
*/
50-
private void updateVoltageLevel(@NonNull SubstationAdapter scdSubstationAdapter, TVoltageLevel vl) throws ScdException {
51-
if (scdSubstationAdapter.getVoltageLevelAdapter(vl.getName()).isPresent()) {
52-
VoltageLevelAdapter scdVoltageLevelAdapter = scdSubstationAdapter.getVoltageLevelAdapter(vl.getName())
53-
.orElseThrow(() -> new ScdException("Unable to create VoltageLevelAdapter"));
54-
for (TBay tbay : vl.getBay()) {
55-
updateBay(scdVoltageLevelAdapter, tbay);
56-
}
57-
} else {
58-
scdSubstationAdapter.getCurrentElem().getVoltageLevel().add(vl);
59-
}
51+
private void updateVoltageLevel(@NonNull SCL scd, TVoltageLevel vl) throws ScdException {
52+
voltageLevelService.findVoltageLevel(scd, tVoltageLevel -> tVoltageLevel.getName().equals(vl.getName()))
53+
.ifPresentOrElse(tVoltageLevel -> vl.getBay().forEach(tBay -> updateBay(tVoltageLevel, tBay)),
54+
()-> scd.getSubstation().getFirst().getVoltageLevel().add(vl));
6055
}
6156

57+
6258
/**
6359
* Adds new Bay in VoltageLevel or if already exist removes and replaces it
64-
* @param scdVoltageLevelAdapter VoltageLevel in which Bay should be created/updated
60+
* @param tVoltageLevel VoltageLevel in which Bay should be created/updated
6561
* @param tBay Bay to add
6662
*/
67-
private void updateBay(@NonNull VoltageLevelAdapter scdVoltageLevelAdapter, TBay tBay) {
68-
if (scdVoltageLevelAdapter.getBayAdapter(tBay.getName()).isPresent()) {
69-
scdVoltageLevelAdapter.getCurrentElem().getBay()
70-
.removeIf(t -> t.getName().equalsIgnoreCase(tBay.getName()));
71-
scdVoltageLevelAdapter.getCurrentElem().getBay().add(tBay);
72-
} else {
73-
scdVoltageLevelAdapter.getCurrentElem().getBay().add(tBay);
74-
}
63+
private void updateBay(@NonNull TVoltageLevel tVoltageLevel, TBay tBay) {
64+
tVoltageLevel.getBay()
65+
.stream().filter(tBay1 -> tBay1.getName().equals(tBay.getName()))
66+
.findFirst()
67+
.ifPresentOrElse(tBay1 -> {
68+
tVoltageLevel.getBay().removeIf(t -> t.getName().equalsIgnoreCase(tBay.getName()));
69+
tVoltageLevel.getBay().add(tBay);
70+
}, ()-> tVoltageLevel.getBay().add(tBay));
7571
}
7672

7773
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-FileCopyrightText: 2024 RTE FRANCE
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sct.commons;
6+
7+
import org.lfenergy.compas.scl2007b4.model.*;
8+
9+
import java.util.Collection;
10+
import java.util.Optional;
11+
import java.util.function.Predicate;
12+
import java.util.stream.Stream;
13+
14+
public class VoltageLevelService {
15+
16+
public Stream<TVoltageLevel> getVoltageLevels(SCL scd) {
17+
if (!scd.isSetSubstation()) {
18+
return Stream.empty();
19+
}
20+
return scd.getSubstation()
21+
.stream()
22+
.map(TSubstation::getVoltageLevel)
23+
.flatMap(Collection::stream);
24+
}
25+
26+
public Optional<TVoltageLevel> findVoltageLevel(SCL scd, Predicate<TVoltageLevel> tVoltageLevelPredicate) {
27+
return getVoltageLevels(scd).filter(tVoltageLevelPredicate).findFirst();
28+
}
29+
}

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/api/HmiEditor.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/scl/ldevice/LDeviceAdapter.java

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,18 @@
1010
import org.lfenergy.compas.scl2007b4.model.*;
1111
import org.lfenergy.compas.sct.commons.dto.*;
1212
import org.lfenergy.compas.sct.commons.exception.ScdException;
13-
import org.lfenergy.compas.sct.commons.model.cb_po.PO;
14-
import org.lfenergy.compas.sct.commons.model.cb_po.TFCDAFilter;
1513
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
1614
import org.lfenergy.compas.sct.commons.scl.dtt.DataTypeTemplateAdapter;
17-
import org.lfenergy.compas.sct.commons.scl.ied.ControlBlockAdapter;
18-
import org.lfenergy.compas.sct.commons.scl.ied.DataSetAdapter;
1915
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;
2016
import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter;
2117
import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter;
2218
import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter;
23-
import org.lfenergy.compas.sct.commons.util.ActiveStatus;
2419
import org.lfenergy.compas.sct.commons.util.ControlBlockEnum;
2520
import org.lfenergy.compas.sct.commons.util.MonitoringLnClassEnum;
2621
import org.lfenergy.compas.sct.commons.util.Utils;
2722

2823
import java.util.*;
2924

30-
import static org.lfenergy.compas.sct.commons.util.CommonConstants.*;
3125
import static org.lfenergy.compas.sct.commons.util.Utils.copySclElement;
3226

3327
/**
@@ -63,10 +57,7 @@
6357
@Slf4j
6458
public class LDeviceAdapter extends SclElementAdapter<IEDAdapter, TLDevice> {
6559

66-
private static final long INTG_PD_VALUE_FOR_FC_MX = 2000L;
67-
6860
private static final String DA_SETSRCREF = "setSrcRef";
69-
private static final String CYC_REPORT_TYPE = "CYC";
7061

7162
/**
7263
* Constructor
@@ -78,43 +69,6 @@ public LDeviceAdapter(IEDAdapter parentAdapter, TLDevice currentElem) {
7869
super(parentAdapter, currentElem);
7970
}
8071

81-
/**
82-
* Create DataSet and ReportControl Blocks for the HMI with the given FCDAs.
83-
* DataSet and ReportControl are created in LN0, even if FCDA refers to another LN.
84-
*
85-
* @param po object containing list of FCDA for which we must create the DataSet and ReportControl
86-
*/
87-
public void createHmiReportControlBlocks(PO po) {
88-
LN0Adapter ln0 = getLN0Adapter();
89-
if (!ln0.getDaiModStValValue().map(ActiveStatus::fromValue).map(ActiveStatus.ON::equals).orElse(false)) return;
90-
po.getFCDAs().getFCDA().stream()
91-
.filter(tfcdaFilter -> getInst().equals(tfcdaFilter.getLdInst()) && tfcdaFilter.isSetLnClass())
92-
.forEach(tfcdaFilter -> (tfcdaFilter.getLnClass().equals(TLLN0Enum.LLN_0.value()) ?
93-
Optional.of(ln0) // ln0 Mod stVal "ON" has already been checked, no need to check it again
94-
:
95-
findLnAdapter(tfcdaFilter.getLnClass(), tfcdaFilter.getLnInst(), tfcdaFilter.getPrefix()).filter(lnAdapter -> lnAdapter.getDaiModStValValue().map(ActiveStatus::fromValue).map(ActiveStatus.ON::equals).orElse(true)))
96-
.map(sourceLn -> sourceLn.getDAI(new DataAttributeRef(toFCDA(tfcdaFilter)), false))
97-
.filter(das -> das.stream().anyMatch(da -> TFCEnum.fromValue(tfcdaFilter.getFc().value()) == da.getFc())) // getDAI does not filter on DA.
98-
.ifPresent(dataAttributeRefs -> createHmiReportCB(ln0, tfcdaFilter)));
99-
}
100-
101-
private void createHmiReportCB(LN0Adapter ln0, TFCDAFilter tfcdaFilter) {
102-
TFCDA fcda = toFCDA(tfcdaFilter);
103-
String dataSetSuffix = getInst().toUpperCase(Locale.ENGLISH) + ATTRIBUTE_VALUE_SEPARATOR + tfcdaFilter.getReportType().substring(0, 2) + "PO";
104-
String dataSetName = DATASET_NAME_PREFIX + dataSetSuffix;
105-
DataSetAdapter dataSet = ln0.createDataSetIfNotExists(dataSetName, ControlBlockEnum.REPORT);
106-
dataSet.createFCDAIfNotExists(fcda.getLdInst(), fcda.getPrefix(), fcda.getLnClass().getFirst(), fcda.getLnInst(), fcda.getDoName(), fcda.getDaName(), fcda.getFc());
107-
String cbName = CONTROLBLOCK_NAME_PREFIX + dataSetSuffix;
108-
String cbId = ln0.generateControlBlockId(getLdName(), cbName);
109-
ControlBlockAdapter controlBlockAdapter = ln0.createControlBlockIfNotExists(cbName, cbId, dataSetName, ControlBlockEnum.REPORT);
110-
if (tfcdaFilter.getReportType().equals(CYC_REPORT_TYPE)) {
111-
TReportControl tReportControl = (TReportControl) controlBlockAdapter.getCurrentElem();
112-
tReportControl.setIntgPd(INTG_PD_VALUE_FOR_FC_MX);
113-
tReportControl.getTrgOps().setDchg(false);
114-
tReportControl.getTrgOps().setQchg(false);
115-
}
116-
}
117-
11872
/**
11973
* Check if node is child of the reference node
12074
*
@@ -483,15 +437,4 @@ private String createVal(TExtRef tExtRef) {
483437
return sourceLdName + "/" + lnClass + "." + tExtRef.getSrcCBName();
484438
}
485439

486-
private TFCDA toFCDA(TFCDAFilter tfcdaFilter) {
487-
TFCDA tfcda = new TFCDA();
488-
tfcda.setLdInst(tfcdaFilter.getLdInst());
489-
tfcda.getLnClass().add(tfcdaFilter.getLnClass());
490-
tfcda.setPrefix(tfcdaFilter.getPrefix());
491-
tfcda.setLnInst(tfcdaFilter.getLnInst());
492-
tfcda.setDoName(tfcdaFilter.getDoName());
493-
tfcda.setFc(TFCEnum.fromValue(tfcdaFilter.getFc().value()));
494-
return tfcda;
495-
}
496-
497440
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public final class Utils {
3131
private static final Pattern MAC_ADDRESS_PATTERN = Pattern.compile("[0-9A-F]{2}([-:][0-9A-F]{2}){5}", Pattern.CASE_INSENSITIVE);
3232

3333
private static JAXBContext jaxbContext = null;
34-
private static Unmarshaller unmarshaller = null;
3534

3635
/**
3736
* Private Constructor, should not be instanced
@@ -149,7 +148,7 @@ public static String xpathAttributeFilter(String name, Collection<String> value)
149148
* @param s1 first string
150149
* @param s2 seconde string
151150
* @return true if strings are equals or both blank, false otherwise
152-
* @see org.apache.commons.lang3.StringUtils#isBlank(CharSequence)
151+
* @see StringUtils#isBlank(CharSequence)
153152
*/
154153
public static boolean equalsOrBothBlank(String s1, String s2) {
155154
return Objects.equals(s1, s2)
@@ -167,9 +166,9 @@ public static boolean equalsOrBothBlank(String s1, String s2) {
167166
* @param s2 second String to compare
168167
* @return when s1 and s2 are not blank, same result as {@link String#compare(CharSequence, CharSequence)},
169168
* zero when s1 and s2 are both blanks, negative integer when s1 is blank and s2 is not, positive integer when s1 is not blank but s2 is.
170-
* @see java.util.Comparator#compare(Object, Object)
171-
* @see org.apache.commons.lang3.StringUtils#isBlank(CharSequence)
172-
* @see java.util.Comparator#nullsFirst(Comparator)
169+
* @see Comparator#compare(Object, Object)
170+
* @see StringUtils#isBlank(CharSequence)
171+
* @see Comparator#nullsFirst(Comparator)
173172
*/
174173
public static int blanksFirstComparator(String s1, String s2) {
175174
if (StringUtils.isBlank(s1)){
@@ -314,11 +313,12 @@ public static String toHex(long number, int length) {
314313
* @return copy of the object
315314
*/
316315
public static <T> T copySclElement(T object, Class<T> clazz) {
316+
Unmarshaller unmarshaller;
317317
try {
318318
if (jaxbContext == null) {
319319
jaxbContext = JAXBContext.newInstance("org.lfenergy.compas.scl2007b4.model");
320-
unmarshaller = jaxbContext.createUnmarshaller();
321320
}
321+
unmarshaller = jaxbContext.createUnmarshaller();
322322
JAXBElement<T> contentObject = new JAXBElement<>(new QName(clazz.getSimpleName()), clazz, object);
323323
JAXBSource source = new JAXBSource(jaxbContext, contentObject);
324324
return unmarshaller.unmarshal(source, clazz).getValue();

0 commit comments

Comments
 (0)