Skip to content

Commit e071955

Browse files
committed
review feedback
Signed-off-by: Samir Romdhani <[email protected]> revert changes related to other issue (Refactor tests structure in compas-sct) Signed-off-by: Samir Romdhani <[email protected]>
1 parent 809106b commit e071955

File tree

18 files changed

+291
-389
lines changed

18 files changed

+291
-389
lines changed

sct-app/src/main/java/org/lfenergy/compas/sct/app/SclAutomationService.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
package org.lfenergy.compas.sct.app;
66

77
import lombok.NonNull;
8-
import org.apache.commons.lang3.tuple.Pair;
98
import org.lfenergy.compas.scl2007b4.model.SCL;
109
import org.lfenergy.compas.sct.commons.dto.HeaderDTO;
1110
import org.lfenergy.compas.sct.commons.dto.SubNetworkDTO;
11+
import org.lfenergy.compas.sct.commons.dto.SubNetworkTypeDTO;
1212
import org.lfenergy.compas.sct.commons.exception.ScdException;
1313
import org.lfenergy.compas.sct.commons.scl.SclService;
1414
import org.lfenergy.compas.sct.commons.scl.SubstationService;
@@ -27,12 +27,12 @@
2727
public class SclAutomationService {
2828

2929
/**
30-
* Possible Subnetwork and ConnectAP names which should be used in generated SCD in order a have global coherence
30+
* Possible Subnetwork and ConnectedAP names which should be used in generated SCD in order a have global coherence
3131
* Configuration based on used framework can be used to externalize this datas
3232
*/
33-
private static final Map<Pair<String, String>, List<String>> comMap = Map.of(
34-
Pair.of("RSPACE_PROCESS_NETWORK", SubNetworkDTO.SubnetworkType.MMS.toString()), Arrays.asList("PROCESS_AP", "TOTO_AP_GE"),
35-
Pair.of("RSPACE_ADMIN_NETWORK", SubNetworkDTO.SubnetworkType.IP.toString()), Arrays.asList("ADMIN_AP", "TATA_AP_EFFACEC"));
33+
public static final List<SubNetworkTypeDTO> SUB_NETWORK_TYPES = List.of(
34+
new SubNetworkTypeDTO("RSPACE_PROCESS_NETWORK", SubNetworkDTO.SubnetworkType.MMS.toString(), List.of("PROCESS_AP", "TOTO_AP_GE")),
35+
new SubNetworkTypeDTO("RSPACE_ADMIN_NETWORK", SubNetworkDTO.SubnetworkType.IP.toString(), List.of("ADMIN_AP", "TATA_AP_EFFACEC")));
3636

3737
private SclAutomationService() {
3838
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
@@ -48,14 +48,13 @@ private SclAutomationService() {
4848
* @throws ScdException
4949
*/
5050
public static SCL createSCD(@NonNull SCL ssd, @NonNull HeaderDTO headerDTO, List<SCL> stds) throws ScdException {
51-
SCL scd = SclService.initScl(Optional.ofNullable(headerDTO.getId()),
52-
headerDTO.getVersion(), headerDTO.getRevision());
51+
SCL scd = SclService.initScl(headerDTO.getId(), headerDTO.getVersion(), headerDTO.getRevision());
5352
if (!headerDTO.getHistoryItems().isEmpty()) {
5453
HeaderDTO.HistoryItem hItem = headerDTO.getHistoryItems().get(0);
5554
SclService.addHistoryItem(scd, hItem.getWho(), hItem.getWhat(), hItem.getWhy());
5655
}
5756
SubstationService.addSubstation(scd, ssd);
58-
SclService.importSTDElementsInSCD(scd, stds, comMap);
57+
SclService.importSTDElementsInSCD(scd, stds, SUB_NETWORK_TYPES);
5958
SclService.removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(scd);
6059
return scd;
6160
}

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.lang.reflect.InvocationTargetException;
2020
import java.util.Arrays;
2121
import java.util.List;
22+
import java.util.UUID;
2223

2324
import static org.assertj.core.api.Assertions.assertThat;
2425
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -32,12 +33,13 @@ class SclAutomationServiceTest {
3233
@BeforeEach
3334
void init() {
3435
headerDTO = new HeaderDTO();
36+
headerDTO.setId(UUID.randomUUID());
3537
headerDTO.setRevision("hRevision");
3638
headerDTO.setVersion("hVersion");
3739
}
3840

3941
@Test
40-
void createSCD_should_return_generatedSCD() throws Exception {
42+
void createSCD_should_return_generatedSCD() {
4143
// Given
4244
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/scd.xml");
4345
SCL std = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml");
@@ -54,7 +56,7 @@ void createSCD_should_return_generatedSCD() throws Exception {
5456
}
5557

5658
@Test
57-
void createSCD_With_HItem() throws Exception {
59+
void createSCD_With_HItem() {
5860
// Given
5961
HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem();
6062
historyItem.setWhat("what");
@@ -100,7 +102,7 @@ void createSCD_With_HItems() {
100102
}
101103

102104
@Test
103-
void createSCD_SSD_Without_Substation() throws Exception {
105+
void createSCD_SSD_Without_Substation() {
104106
// Given
105107
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd_without_substations.xml");
106108
// When & Then
@@ -110,7 +112,7 @@ void createSCD_SSD_Without_Substation() throws Exception {
110112
}
111113

112114
@Test
113-
void createSCD_should_throw_exception_when_null_ssd() throws Exception {
115+
void createSCD_should_throw_exception_when_null_ssd() {
114116
// Given
115117
HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem();
116118
historyItem.setWhat("what");
@@ -125,7 +127,7 @@ void createSCD_should_throw_exception_when_null_ssd() throws Exception {
125127
}
126128

127129
@Test
128-
void createSCD_should_throw_exception_when_null_headerDTO() throws Exception {
130+
void createSCD_should_throw_exception_when_null_headerDTO() {
129131
// Given
130132
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd.xml");
131133
SCL std1 = SclTestMarshaller.getSCLFromFile("/std_1.xml");
@@ -136,7 +138,7 @@ void createSCD_should_throw_exception_when_null_headerDTO() throws Exception {
136138
}
137139

138140
@Test
139-
void createSCD_should_delete_ControlBlocks_DataSet_and_ExtRef_src_attributes() throws Exception {
141+
void createSCD_should_delete_ControlBlocks_DataSet_and_ExtRef_src_attributes() {
140142
// Given
141143
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/ssd.xml");
142144
SCL std = SclTestMarshaller.getSCLFromFile("/scl-remove-controlBlocks-dataSet-extRefSrc/scl-with-control-blocks.xml");

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/ConnectedApDTO.java

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44

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

7-
8-
import lombok.AllArgsConstructor;
9-
import lombok.Getter;
10-
import lombok.NoArgsConstructor;
11-
import lombok.Setter;
127
import org.lfenergy.compas.sct.commons.scl.com.ConnectedAPAdapter;
138

149
/**
@@ -18,39 +13,22 @@
1813
* The following features are supported:
1914
* </p>
2015
* <ul>
21-
* <li>{@link ConnectedApDTO#getApName() <em>Ap Name</em>}</li>
22-
* <li>{@link ConnectedApDTO#getIedName() <em>Ied Name</em>}</li>
16+
* <li>{@link ConnectedApDTO#apName()} () <em>Ap Name</em>}</li>
17+
* <li>{@link ConnectedApDTO#iedName()} () <em>Ied Name</em>}</li>
2318
* </ul>
2419
*
2520
* @see org.lfenergy.compas.scl2007b4.model.TConnectedAP
2621
*/
27-
@Setter
28-
@Getter
29-
@NoArgsConstructor
30-
@AllArgsConstructor
31-
public class ConnectedApDTO {
32-
private String iedName;
33-
private String apName;
34-
35-
/**
36-
* Create ConnectedApDTO from constructor
37-
* @param connectedAPAdapter object containing data to use
38-
*/
39-
public ConnectedApDTO(ConnectedAPAdapter connectedAPAdapter) {
40-
this.iedName = connectedAPAdapter.getIedName();
41-
this.apName = connectedAPAdapter.getApName();
42-
}
22+
public record ConnectedApDTO(String iedName, String apName) {
4323

4424
/**
4525
* Convert ConnectedAPAdapter object to dto ConnectedApDTO
26+
*
4627
* @param connectedAPAdapter object to convert
4728
* @return dto ConnectedApDTO
4829
*/
4930
public static ConnectedApDTO from(ConnectedAPAdapter connectedAPAdapter) {
50-
ConnectedApDTO connectedApDTO = new ConnectedApDTO();
51-
connectedApDTO.iedName = connectedAPAdapter.getIedName();
52-
connectedApDTO.apName = connectedAPAdapter.getApName();
53-
54-
return connectedApDTO;
31+
return new ConnectedApDTO(connectedAPAdapter.getIedName(), connectedAPAdapter.getApName());
5532
}
33+
5634
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SPDX-FileCopyrightText: 2023 RTE FRANCE
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sct.commons.dto;
6+
7+
public record EnumValDTO(Integer ord, String value) {
8+
}

sct-commons/src/main/java/org/lfenergy/compas/sct/commons/dto/SubNetworkDTO.java

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@
88
import com.fasterxml.jackson.annotation.JsonValue;
99
import lombok.Getter;
1010
import lombok.NoArgsConstructor;
11-
import org.apache.commons.lang3.tuple.Pair;
12-
import org.lfenergy.compas.sct.commons.scl.com.CommunicationAdapter;
13-
import org.lfenergy.compas.sct.commons.scl.com.ConnectedAPAdapter;
11+
import org.lfenergy.compas.scl2007b4.model.TCommunication;
12+
import org.lfenergy.compas.scl2007b4.model.TConnectedAP;
13+
import org.lfenergy.compas.scl2007b4.model.TSubNetwork;
1414
import org.lfenergy.compas.sct.commons.scl.com.SubNetworkAdapter;
1515

16-
import java.util.HashSet;
17-
import java.util.List;
18-
import java.util.Map;
19-
import java.util.Set;
20-
import java.util.stream.Collectors;
16+
import java.util.*;
2117

2218
/**
2319
* A representation of the model object <em><b>Sub Network</b></em>.
@@ -39,7 +35,7 @@ public class SubNetworkDTO {
3935

4036
private String name;
4137
private SubnetworkType type;
42-
private Set<ConnectedApDTO> connectedAPs = new HashSet<>();
38+
private final Set<ConnectedApDTO> connectedAPs = new HashSet<>();
4339

4440
/**
4541
* Constructor
@@ -145,20 +141,21 @@ public static SubnetworkType fromValue(String text) {
145141
}
146142

147143
/**
148-
* Create default SubnetworkType in Communication node of SCL file
149-
* @param iedName name of existing IED in SCL
150-
* @param comAdapter Communication node Adapter object value
151-
* @param comMap possible name of SubnetworkTypes and corresponding ConnectedAPs
152-
* @return
144+
* Create default Subnetwork in Communication node of SCL file
145+
* @param iedName Name of existing IED in SCL
146+
* @param communication Communication node in SCL
147+
* @param subNetworkTypes Possible name of Subnetwork and corresponding ConnectedAPs
148+
* @return List of Subnetwork
153149
*/
154-
public static Set<SubNetworkDTO> createDefaultSubnetwork(String iedName, CommunicationAdapter comAdapter, Map<Pair<String, String>, List<String>> comMap){
155-
Set<SubNetworkDTO> subNetworkDTOS = new HashSet<>();
156-
comMap.forEach((subnetworkNameType, apNames) -> {
157-
SubNetworkDTO subNetworkDTO = new SubNetworkDTO(subnetworkNameType.getLeft(), subnetworkNameType.getRight());
158-
apNames.forEach(s -> {
159-
if(getStdConnectedApNames(comAdapter).contains(s)){
160-
ConnectedApDTO connectedApDTO = new ConnectedApDTO(iedName, s);
161-
subNetworkDTO.addConnectedAP(connectedApDTO);}
150+
public static List<SubNetworkDTO> createDefaultSubnetwork(String iedName, TCommunication communication, List<SubNetworkTypeDTO> subNetworkTypes){
151+
List<SubNetworkDTO> subNetworkDTOS = new ArrayList<>();
152+
subNetworkTypes.forEach(subnetwork -> {
153+
SubNetworkDTO subNetworkDTO = new SubNetworkDTO(subnetwork.subnetworkName(), subnetwork.subnetworkType());
154+
subnetwork.accessPointNames().forEach(accessPointName -> {
155+
if(getStdConnectedApNames(communication).contains(accessPointName)){
156+
ConnectedApDTO connectedApDTO = new ConnectedApDTO(iedName, accessPointName);
157+
subNetworkDTO.addConnectedAP(connectedApDTO);
158+
}
162159
});
163160
subNetworkDTOS.add(subNetworkDTO);
164161
});
@@ -167,13 +164,15 @@ public static Set<SubNetworkDTO> createDefaultSubnetwork(String iedName, Communi
167164

168165
/**
169166
* Gets ConnectedAP name's from Communication node
170-
* @param comAdapter Communication node object value
171-
* @return
167+
* @param communication Communication node object value
168+
* @return List of ConnectedAP names
172169
*/
173-
private static List<String> getStdConnectedApNames(CommunicationAdapter comAdapter){
174-
return comAdapter.getSubNetworkAdapters().stream()
175-
.map(SubNetworkAdapter::getConnectedAPAdapters)
176-
.flatMap(connectedAPAdapters -> connectedAPAdapters.stream().map(ConnectedAPAdapter::getApName))
177-
.collect(Collectors.toList());
170+
private static List<String> getStdConnectedApNames(TCommunication communication){
171+
return communication.getSubNetwork().stream()
172+
.map(TSubNetwork::getConnectedAP)
173+
.flatMap(List::stream)
174+
.map(TConnectedAP::getApName)
175+
.toList();
178176
}
177+
179178
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-FileCopyrightText: 2023 RTE FRANCE
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sct.commons.dto;
6+
7+
import java.util.List;
8+
9+
public record SubNetworkTypeDTO(String subnetworkName, String subnetworkType, List<String> accessPointNames) {
10+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static List<SclReportItem> updateAllExtRefIedNames(SCL scd) {
5959
.filter(LN0Adapter::hasInputs)
6060
.map(LN0Adapter::getInputsAdapter)
6161
.map(inputsAdapter -> inputsAdapter.updateAllExtRefIedNames(icdSystemVersionToIed))
62-
.flatMap(List::stream).collect(Collectors.toList());
62+
.flatMap(List::stream).toList();
6363
}
6464

6565
private static List<SclReportItem> validateIed(SclRootAdapter sclRootAdapter) {
@@ -152,7 +152,7 @@ private static List<SclReportItem> createDataSetAndControlBlocks(Stream<LDeviceA
152152
return lDeviceAdapters
153153
.map(LDeviceAdapter::createDataSetAndControlBlocks)
154154
.flatMap(List::stream)
155-
.collect(Collectors.toList());
155+
.toList();
156156
}
157157

158158
/**

0 commit comments

Comments
 (0)