Skip to content

Commit cd893b9

Browse files
Merge pull request #310 from com-pas/develop
Merge develop into main
2 parents df8ff61 + 8b8c2ce commit cd893b9

36 files changed

+648
-838
lines changed

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
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;
13-
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
1413
import org.lfenergy.compas.sct.commons.scl.SclService;
1514
import org.lfenergy.compas.sct.commons.scl.SubstationService;
1615

@@ -22,42 +21,41 @@
2221
* The following features are supported:
2322
* </p>
2423
* <ul>
25-
* <li>{@link SclAutomationService#createSCD(SCL, HeaderDTO, Set) Adds all elements under the <b>SCL </b> object from given <b>SSD </b> and <b>STD </b> files}
24+
* <li>{@link SclAutomationService#createSCD(SCL, HeaderDTO, List) Adds all elements under the <b>SCL </b> object from given <b>SSD </b> and <b>STD </b> files}
2625
* </ul>
2726
*/
2827
public class SclAutomationService {
2928

3029
/**
31-
* 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
3231
* Configuration based on used framework can be used to externalize this datas
3332
*/
34-
private static final Map<Pair<String, String>, List<String>> comMap = Map.of(
35-
Pair.of("RSPACE_PROCESS_NETWORK", SubNetworkDTO.SubnetworkType.MMS.toString()), Arrays.asList("PROCESS_AP", "TOTO_AP_GE"),
36-
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")));
3736

3837
private SclAutomationService() {
3938
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
4039
}
4140

4241
/**
43-
* Create a SCD file from specified parameters, it calls all functions defined in the process one by one, every step
44-
* return a SCD file which will be used by the next step.
42+
* Create an SCD file from specified parameters, it calls all functions defined in the process one by one, every step
43+
* return an SCD file which will be used by the next step.
4544
* @param ssd : (mandatory) file contains substation datas
4645
* @param headerDTO : (mandatory) object which hold header datas and historys' one
47-
* @param stds : (optional) list of STD files containing IED datas (IED, Communication and DataTypeTemplate)
48-
* @return a SCD file encapsuled in object SclRootAdapter
46+
* @param stds : list of STD files containing IED datas (IED, Communication and DataTypeTemplate)
47+
* @return an SCD object
4948
* @throws ScdException
5049
*/
51-
public static SclRootAdapter createSCD(@NonNull SCL ssd, @NonNull HeaderDTO headerDTO, Set<SCL> stds) throws ScdException {
52-
SclRootAdapter scdAdapter = SclService.initScl(Optional.ofNullable(headerDTO.getId()),
53-
headerDTO.getVersion(), headerDTO.getRevision());
50+
public static SCL createSCD(@NonNull SCL ssd, @NonNull HeaderDTO headerDTO, List<SCL> stds) throws ScdException {
51+
SCL scd = SclService.initScl(headerDTO.getId(), headerDTO.getVersion(), headerDTO.getRevision());
5452
if (!headerDTO.getHistoryItems().isEmpty()) {
5553
HeaderDTO.HistoryItem hItem = headerDTO.getHistoryItems().get(0);
56-
SclService.addHistoryItem(scdAdapter.getCurrentElem(), hItem.getWho(), hItem.getWhat(), hItem.getWhy());
54+
SclService.addHistoryItem(scd, hItem.getWho(), hItem.getWhat(), hItem.getWhy());
5755
}
58-
SubstationService.addSubstation(scdAdapter.getCurrentElem(), ssd);
59-
SclService.importSTDElementsInSCD(scdAdapter, stds, comMap);
60-
SclService.removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(scdAdapter.getCurrentElem());
61-
return scdAdapter;
56+
SubstationService.addSubstation(scd, ssd);
57+
SclService.importSTDElementsInSCD(scd, stds, SUB_NETWORK_TYPES);
58+
SclService.removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(scd);
59+
return scd;
6260
}
6361
}

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

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import java.lang.reflect.Constructor;
1919
import java.lang.reflect.InvocationTargetException;
2020
import java.util.Arrays;
21-
import java.util.HashSet;
22-
import java.util.Set;
21+
import java.util.List;
22+
import java.util.UUID;
2323

2424
import static org.assertj.core.api.Assertions.assertThat;
2525
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -33,29 +33,30 @@ class SclAutomationServiceTest {
3333
@BeforeEach
3434
void init() {
3535
headerDTO = new HeaderDTO();
36+
headerDTO.setId(UUID.randomUUID());
3637
headerDTO.setRevision("hRevision");
3738
headerDTO.setVersion("hVersion");
3839
}
3940

4041
@Test
41-
void createSCD_should_return_generatedSCD() throws Exception {
42+
void createSCD_should_return_generatedSCD() {
4243
// Given
4344
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/scd.xml");
4445
SCL std = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/std.xml");
4546
// When
46-
SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO, Set.of(std));
47+
SCL scd = SclAutomationService.createSCD(ssd, headerDTO, List.of(std));
4748
// Then
48-
assertNotNull(expectedSCD.getCurrentElem().getHeader().getId());
49-
assertNull(expectedSCD.getCurrentElem().getHeader().getHistory());
50-
assertEquals(1, expectedSCD.getCurrentElem().getSubstation().size());
51-
assertEquals(1, expectedSCD.getCurrentElem().getIED().size());
52-
assertNotNull(expectedSCD.getCurrentElem().getDataTypeTemplates());
53-
assertEquals(2, expectedSCD.getCurrentElem().getCommunication().getSubNetwork().size());
54-
assertIsMarshallable(expectedSCD.getCurrentElem());
49+
assertNotNull(scd.getHeader().getId());
50+
assertNull(scd.getHeader().getHistory());
51+
assertEquals(1, scd.getSubstation().size());
52+
assertEquals(1, scd.getIED().size());
53+
assertNotNull(scd.getDataTypeTemplates());
54+
assertEquals(2, scd.getCommunication().getSubNetwork().size());
55+
assertIsMarshallable(scd);
5556
}
5657

5758
@Test
58-
void createSCD_With_HItem() throws Exception {
59+
void createSCD_With_HItem() {
5960
// Given
6061
HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem();
6162
historyItem.setWhat("what");
@@ -67,16 +68,16 @@ void createSCD_With_HItem() throws Exception {
6768
SCL std2 = SclTestMarshaller.getSCLFromFile("/std_2.xml");
6869
SCL std3 = SclTestMarshaller.getSCLFromFile("/std_3.xml");
6970
// When
70-
SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO, Set.of(std1, std2, std3));
71+
SCL scd = SclAutomationService.createSCD(ssd, headerDTO, List.of(std1, std2, std3));
7172
// Then
72-
assertNotNull(expectedSCD.getCurrentElem().getHeader().getId());
73-
assertEquals(1, expectedSCD.getCurrentElem().getHeader().getHistory().getHitem().size());
74-
assertEquals(1, expectedSCD.getCurrentElem().getSubstation().size());
75-
assertIsMarshallable(expectedSCD.getCurrentElem());
73+
assertNotNull(scd.getHeader().getId());
74+
assertEquals(1, scd.getHeader().getHistory().getHitem().size());
75+
assertEquals(1, scd.getSubstation().size());
76+
assertIsMarshallable(scd);
7677
}
7778

7879
@Test
79-
void createSCD_With_HItems() throws Exception {
80+
void createSCD_With_HItems() {
8081
// Given
8182
HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem();
8283
historyItem.setWhat("what");
@@ -92,59 +93,59 @@ void createSCD_With_HItems() throws Exception {
9293
SCL std2 = SclTestMarshaller.getSCLFromFile("/std_2.xml");
9394
SCL std3 = SclTestMarshaller.getSCLFromFile("/std_3.xml");
9495
// When
95-
SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO, Set.of(std1, std2, std3));
96+
SCL scd = SclAutomationService.createSCD(ssd, headerDTO, List.of(std1, std2, std3));
9697
// Then
97-
assertNotNull(expectedSCD.getCurrentElem().getHeader().getId());
98-
assertEquals(1, expectedSCD.getCurrentElem().getHeader().getHistory().getHitem().size());
99-
assertEquals("what", expectedSCD.getCurrentElem().getHeader().getHistory().getHitem().get(0).getWhat());
100-
assertIsMarshallable(expectedSCD.getCurrentElem());
98+
assertNotNull(scd.getHeader().getId());
99+
assertEquals(1, scd.getHeader().getHistory().getHitem().size());
100+
assertEquals("what", scd.getHeader().getHistory().getHitem().get(0).getWhat());
101+
assertIsMarshallable(scd);
101102
}
102103

103104
@Test
104-
void createSCD_SSD_Without_Substation() throws Exception {
105+
void createSCD_SSD_Without_Substation() {
105106
// Given
106107
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd_without_substations.xml");
107108
// When & Then
108-
Set<SCL> stdListEmpty = new HashSet<>();
109+
List<SCL> stdListEmpty = List.of();
109110
assertThrows(ScdException.class,
110111
() -> SclAutomationService.createSCD(ssd, headerDTO, stdListEmpty));
111112
}
112113

113114
@Test
114-
void createSCD_should_throw_exception_when_null_ssd() throws Exception {
115+
void createSCD_should_throw_exception_when_null_ssd() {
115116
// Given
116117
HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem();
117118
historyItem.setWhat("what");
118119
historyItem.setWho("me");
119120
historyItem.setWhy("because");
120121
headerDTO.getHistoryItems().add(historyItem);
121122
SCL std1 = SclTestMarshaller.getSCLFromFile("/std_1.xml");
122-
Set<SCL> stdList = Set.of(std1);
123+
List<SCL> stdList = List.of(std1);
123124

124125
// When & Then
125126
assertThrows(NullPointerException.class, () -> SclAutomationService.createSCD(null, headerDTO, stdList));
126127
}
127128

128129
@Test
129-
void createSCD_should_throw_exception_when_null_headerDTO() throws Exception {
130+
void createSCD_should_throw_exception_when_null_headerDTO() {
130131
// Given
131132
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd.xml");
132133
SCL std1 = SclTestMarshaller.getSCLFromFile("/std_1.xml");
133-
Set<SCL> stdList = Set.of(std1);
134+
List<SCL> stdList = List.of(std1);
134135

135136
// When & Then
136137
assertThrows(NullPointerException.class, () -> SclAutomationService.createSCD(ssd, null, stdList));
137138
}
138139

139140
@Test
140-
void createSCD_should_delete_ControlBlocks_DataSet_and_ExtRef_src_attributes() throws Exception {
141+
void createSCD_should_delete_ControlBlocks_DataSet_and_ExtRef_src_attributes() {
141142
// Given
142143
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-ied-dtt-com-import-stds/ssd.xml");
143144
SCL std = SclTestMarshaller.getSCLFromFile("/scl-remove-controlBlocks-dataSet-extRefSrc/scl-with-control-blocks.xml");
144145
// When
145-
SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO, Set.of(std));
146+
SCL scd = SclAutomationService.createSCD(ssd, headerDTO, List.of(std));
146147
// Then
147-
LN0 ln0 = expectedSCD.streamIEDAdapters()
148+
LN0 ln0 = new SclRootAdapter(scd).streamIEDAdapters()
148149
.findFirst()
149150
.map(iedAdapter -> iedAdapter.findLDeviceAdapterByLdInst("lDeviceInst1").orElseThrow())
150151
.map(LDeviceAdapter::getLN0Adapter)
@@ -154,7 +155,7 @@ void createSCD_should_delete_ControlBlocks_DataSet_and_ExtRef_src_attributes() t
154155
assertThat(ln0.getDataSet()).isEmpty();
155156
assertThat(ln0.getInputs().getExtRef()).hasSize(2);
156157
assertFalse(ln0.getInputs().getExtRef().get(0).isSetSrcLDInst());
157-
assertIsMarshallable(expectedSCD.getCurrentElem());
158+
assertIsMarshallable(scd);
158159
}
159160

160161
@Test

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

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,33 @@
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

9+
import java.util.Objects;
10+
1411
/**
1512
* A representation of the model object <em><b>Connected AP</b></em>.
1613
*
1714
* <p>
1815
* The following features are supported:
1916
* </p>
2017
* <ul>
21-
* <li>{@link ConnectedApDTO#getApName() <em>Ap Name</em>}</li>
22-
* <li>{@link ConnectedApDTO#getIedName() <em>Ied Name</em>}</li>
18+
* <li>{@link ConnectedApDTO#apName()} () <em>Ap Name</em>}</li>
19+
* <li>{@link ConnectedApDTO#iedName()} () <em>Ied Name</em>}</li>
2320
* </ul>
2421
*
2522
* @see org.lfenergy.compas.scl2007b4.model.TConnectedAP
2623
*/
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-
}
24+
public record ConnectedApDTO(String iedName, String apName) {
4325

4426
/**
4527
* Convert ConnectedAPAdapter object to dto ConnectedApDTO
28+
*
4629
* @param connectedAPAdapter object to convert
4730
* @return dto ConnectedApDTO
4831
*/
4932
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;
33+
return new ConnectedApDTO(connectedAPAdapter.getIedName(), connectedAPAdapter.getApName());
5534
}
35+
5636
}
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/SclReport.java

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

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1-
// SPDX-FileCopyrightText: 2022 RTE FRANCE
1+
// SPDX-FileCopyrightText: 2022 2023 RTE FRANCE
22
//
33
// SPDX-License-Identifier: Apache-2.0
44

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

7-
import lombok.AllArgsConstructor;
8-
import lombok.EqualsAndHashCode;
9-
import lombok.Getter;
10-
import lombok.ToString;
7+
public record SclReportItem(String xpath, String message, boolean isError) {
118

12-
@Getter
13-
@EqualsAndHashCode
14-
@AllArgsConstructor
15-
@ToString
16-
public final class SclReportItem {
17-
private final String xpath;
18-
private final String message;
19-
private final boolean isFatal;
20-
21-
public static SclReportItem fatal(String xpath, String message) {
9+
public static SclReportItem error(String xpath, String message) {
2210
return new SclReportItem(xpath, message, true);
2311
}
2412

0 commit comments

Comments
 (0)