Skip to content

Commit c13fce6

Browse files
committed
refactor(#110): Create interface for Services and replace static methods with instance methods
closes #110 BREAKING CHANGE: 💥 in sct-commons: The services which provide static methods are moved from scl to commons package. Now those services implements interfaces, no static methods. Expect for PrivateService which is an UtilityClass is renamed to PrivateUtils and moved from scl to util package. Signed-off-by: Samir Romdhani <[email protected]> refactor(#110): give PrivateService the new name PrivateUtils and change the package from scl to util. Changing the name of PrivateService to PrivateUtils and move it from scl to util package , closes #110 refactor(#110): update SclAutomationService Signed-off-by: Samir Romdhani <[email protected]> refactor(#110): check review part1 use @requiredargsconstructor, instead of @NoArgsConstructor. use Camel case for PrivateLinkedToStds Signed-off-by: Samir Romdhani <[email protected]> refactor(#110): check review part2 [use mockito properly] Remove unused test package. Use latest version of mockito. Fix related to version 5.4.0 Signed-off-by: Samir Romdhani <[email protected]> refactor(#110): review part3 [naming] remove prefix 'I' and add suffix 'Editor' The interfaces are moved from scl to api package. add package doc Signed-off-by: Samir Romdhani <[email protected]> refactor(#110): review part4 [seperate SclService features ] SclEditor (interface) spec are reduced by adding ReadOnly and Write One Signed-off-by: Samir Romdhani <[email protected]> refactor(#110): sonar review Signed-off-by: Samir Romdhani <[email protected]> docs(#110): update demo project and quickstart page Signed-off-by: Samir Romdhani <[email protected]>
1 parent 985b66e commit c13fce6

40 files changed

+2100
-1768
lines changed

docs/QUICK_START.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- SPDX-FileCopyrightText: 2022 RTE FRANCE -->
1+
<!-- SPDX-FileCopyrightText: 2022 2023 RTE FRANCE -->
22
<!-- -->
33
<!-- SPDX-License-Identifier: Apache-2.0 -->
44
# CoMPAS SCT (Substation Configuration Tool)
@@ -17,13 +17,13 @@ First you need to add following dependencies to the pom.xml of your repository.
1717
<dependency>
1818
<groupId>org.lfenergy.compas</groupId>
1919
<artifactId>sct-commons</artifactId>
20-
<version>0.1.0</version>
20+
<version>0.2.12</version>
2121
</dependency>
2222
<!-- SclAutomationService -->
2323
<dependency>
2424
<groupId>org.lfenergy.compas</groupId>
2525
<artifactId>sct-app</artifactId>
26-
<version>0.1.0</version>
26+
<version>0.2.12</version>
2727
</dependency>
2828
```
2929
Actually there are 4 packages available:
@@ -37,15 +37,20 @@ Actually there are 4 packages available:
3737
Now that you have your **compas-sct** dependency set, you can start communicating with Commons SCT services.
3838

3939
**sct-commons** provides a collection of services to help you build SCL files for a range of use cases.
40+
4041
Following services provides needed functions compliant with IEC 61850 :
4142

42-
1. **SclService**
43-
2. **SubstationService**
43+
1. **SclEditorService**
44+
2. **SclElementsProviderService**
45+
3. **SubstationService**
46+
4. **ExtRefService**
47+
5. **HmiService**
4448

4549
Let's start with a simple **SclService** call
4650

4751
```java
48-
var scl = SclService.initScl(Optional.empty(), "1.0", "1.0");
52+
SclEditor sclEditorService = new SclEditorService();
53+
SCL scl = sclEditorService.initScl(UUID.randomUUID(), "1.0", "1.0");
4954
marshaller.marshal(scl.getCurrentElem(), System.out);
5055
```
5156

@@ -78,11 +83,15 @@ Start it by using existing files of type `SSD` and `STD` and
7883
running the following :
7984

8085
```java
81-
// ssd : SSD
82-
// std : STD
86+
// ssd : SCL object represent an SSD file
87+
// std : SCL object represent an STD file
88+
SclEditor sclService = new SclEditorService();
89+
SubstationEditor substationService = new SubstationService();
8390
HeaderDTO headerDTO = new HeaderDTO(UUID.randomUUID(), "1.0", "1.0");
84-
var scl = SclAutomationService.createSCD(ssd, headerDTO, Set.of(std));
85-
marshaller.marshal(scl.getCurrentElem(), System.out);
91+
92+
SclAutomationService sclAutomationService = new SclAutomationService(sclService, substationService);
93+
SCL scl = sclAutomationService.createSCD(ssd, headerDTO, List.of(std));
94+
marshaller.marshal(scl, System.out);
8695
```
8796
When the command completes, it prints XML output representing completed **SCL** file.
8897
Its structure resembles the following:

docs/examples/example-app/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ SPDX-License-Identifier: Apache-2.0
1818

1919
<properties>
2020
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21-
<maven.compiler.source>11</maven.compiler.source>
22-
<maven.compiler.target>11</maven.compiler.target>
23-
<maven.compiler.release>11</maven.compiler.release>
21+
<maven.compiler.source>17</maven.compiler.source>
22+
<maven.compiler.target>17</maven.compiler.target>
23+
<maven.compiler.release>17</maven.compiler.release>
2424
</properties>
2525

2626
<distributionManagement>
@@ -44,13 +44,13 @@ SPDX-License-Identifier: Apache-2.0
4444
<dependency>
4545
<groupId>org.lfenergy.compas</groupId>
4646
<artifactId>sct-commons</artifactId>
47-
<version>0.1.0</version>
47+
<version>0.2.12</version>
4848
</dependency>
4949
<!-- SclAutomationService -->
5050
<dependency>
5151
<groupId>org.lfenergy.compas</groupId>
5252
<artifactId>sct-app</artifactId>
53-
<version>0.1.0</version>
53+
<version>0.2.12</version>
5454
</dependency>
5555
<dependency>
5656
<groupId>org.junit.jupiter</groupId>

docs/examples/example-app/src/main/java/org/lfenergy/compas/sct/examples/SctAppExample.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
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.examples;
66

77
import org.lfenergy.compas.scl2007b4.model.SCL;
8-
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
9-
import org.lfenergy.compas.sct.commons.scl.SclService;
8+
import org.lfenergy.compas.sct.commons.SclEditorService;
9+
import org.lfenergy.compas.sct.commons.api.SclEditor;
1010

1111
import javax.xml.bind.JAXBContext;
1212
import javax.xml.bind.JAXBException;
1313
import javax.xml.bind.Marshaller;
14-
import java.util.Optional;
1514
import java.util.UUID;
1615

1716
public class SctAppExample {
1817

18+
private static final SclEditor sclEditor = new SclEditorService();
19+
1920
public static void main( String[] args ) throws JAXBException {
20-
initSclWithSclService(Optional.empty(), "1.0", "1.0");
21+
initSclWithSclService(UUID.randomUUID(), "1.0", "1.0");
2122
}
2223

23-
public static SclRootAdapter initSclWithSclService(Optional<UUID> hId, String hVersion, String hRevision) throws JAXBException {
24-
SclRootAdapter scl = SclService.initScl(hId, hVersion, hRevision);
25-
marshaller.marshal(scl.getCurrentElem(), System.out);
24+
public static SCL initSclWithSclService(UUID hId, String hVersion, String hRevision) throws JAXBException {
25+
SCL scl = sclEditor.initScl(hId, hVersion, hRevision);
26+
marshaller.marshal(scl, System.out);
2627
return scl;
2728
}
2829

29-
private static Marshaller marshaller;
30+
private static final Marshaller marshaller;
3031
static{
3132
try {
3233
JAXBContext context = JAXBContext.newInstance(SCL.class);

docs/examples/example-app/src/test/java/org/lfenergy/compas/sct/examples/SctAppExampleTest.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,36 @@
1010

1111
import javax.xml.bind.JAXBException;
1212
import java.util.List;
13-
import java.util.Optional;
1413
import java.util.UUID;
1514

16-
import static org.junit.jupiter.api.Assertions.*;
15+
import static org.assertj.core.api.Assertions.assertThat;
1716

1817

19-
public class SctAppExampleTest {
18+
class SctAppExampleTest {
2019

2120
@Test
22-
public void initSclWithSclServiceTest() throws JAXBException {
21+
void initSclWithSclServiceTest() throws JAXBException {
2322
// Given : Header attributes
24-
Optional<UUID> headerId = Optional.of(UUID.randomUUID());
23+
UUID headerId = UUID.randomUUID();
2524
String headerVersion = SclRootAdapter.VERSION;
2625
String headerRevision = SclRootAdapter.REVISION;
2726
// When: Sct Service
28-
SclRootAdapter scl = SctAppExample
29-
.initSclWithSclService(headerId, headerVersion, headerRevision);
27+
SCL scl = SctAppExample.initSclWithSclService(headerId, headerVersion, headerRevision);
3028
// Then
31-
assertNotNull(scl.getCurrentElem().getHeader());
32-
assertEquals(headerId.get().toString(), scl.getCurrentElem().getHeader().getId());
33-
assertEquals(headerVersion, scl.getCurrentElem().getHeader().getVersion());
34-
assertEquals(headerRevision, scl.getCurrentElem().getHeader().getRevision());
35-
THeader.History history = scl.getCurrentElem().getHeader().getHistory();
36-
List<TSubstation> substations = scl.getCurrentElem().getSubstation();
37-
TCommunication communication = scl.getCurrentElem().getCommunication();
38-
List<TIED> iedList = scl.getCurrentElem().getIED();
39-
TDataTypeTemplates dataTypeTemplates = scl.getCurrentElem().getDataTypeTemplates();
40-
assertNull(history);
41-
assertEquals(0, substations.size());
42-
assertNull(communication);
43-
assertEquals(0, iedList.size());
44-
assertNull(dataTypeTemplates);
29+
assertThat(scl.getHeader()).isNotNull();
30+
assertThat(scl.getHeader().getId()).isEqualTo(headerId.toString());
31+
assertThat(scl.getHeader().getVersion()).isEqualTo(headerVersion);
32+
assertThat(scl.getHeader().getRevision()).isEqualTo(headerRevision);
33+
THeader.History history = scl.getHeader().getHistory();
34+
List<TSubstation> substations = scl.getSubstation();
35+
TCommunication communication = scl.getCommunication();
36+
List<TIED> iedList = scl.getIED();
37+
TDataTypeTemplates dataTypeTemplates = scl.getDataTypeTemplates();
38+
assertThat(history).isNull();
39+
assertThat(substations).isEmpty();
40+
assertThat(communication).isNull();
41+
assertThat(iedList).isEmpty();
42+
assertThat(dataTypeTemplates).isNull();
4543
}
4644

4745
}

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<logback-classic.version>1.4.5</logback-classic.version>
4545
<assertj.version>3.22.0</assertj.version>
4646
<lombok.version>1.18.24</lombok.version>
47+
<mockito.version>5.5.0</mockito.version>
4748
<jackson-databind.version>2.13.4.1</jackson-databind.version>
4849
</properties>
4950

@@ -78,6 +79,18 @@
7879
<version>${junit-version}</version>
7980
<scope>test</scope>
8081
</dependency>
82+
<dependency>
83+
<groupId>org.mockito</groupId>
84+
<artifactId>mockito-core</artifactId>
85+
<version>${mockito.version}</version>
86+
<scope>test</scope>
87+
</dependency>
88+
<dependency>
89+
<groupId>org.mockito</groupId>
90+
<artifactId>mockito-junit-jupiter</artifactId>
91+
<version>${mockito.version}</version>
92+
<scope>test</scope>
93+
</dependency>
8194
<dependency>
8295
<groupId>org.lfenergy.compas.core</groupId>
8396
<artifactId>scl-extension</artifactId>

sct-app/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@
5858
<groupId>org.assertj</groupId>
5959
<artifactId>assertj-core</artifactId>
6060
</dependency>
61+
<dependency>
62+
<groupId>org.mockito</groupId>
63+
<artifactId>mockito-core</artifactId>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.mockito</groupId>
67+
<artifactId>mockito-junit-jupiter</artifactId>
68+
</dependency>
6169
</dependencies>
6270
<build>
6371
<plugins>

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

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

77
import lombok.NonNull;
8+
import lombok.RequiredArgsConstructor;
89
import org.lfenergy.compas.scl2007b4.model.SCL;
10+
import org.lfenergy.compas.sct.commons.api.SclEditor;
11+
import org.lfenergy.compas.sct.commons.api.SubstationEditor;
912
import org.lfenergy.compas.sct.commons.dto.HeaderDTO;
1013
import org.lfenergy.compas.sct.commons.dto.SubNetworkDTO;
1114
import org.lfenergy.compas.sct.commons.dto.SubNetworkTypeDTO;
1215
import org.lfenergy.compas.sct.commons.exception.ScdException;
13-
import org.lfenergy.compas.sct.commons.scl.SclService;
14-
import org.lfenergy.compas.sct.commons.scl.SubstationService;
1516

1617
import java.util.*;
1718

@@ -24,8 +25,12 @@
2425
* <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}
2526
* </ul>
2627
*/
28+
@RequiredArgsConstructor
2729
public class SclAutomationService {
2830

31+
private final SclEditor sclEditor;
32+
private final SubstationEditor substationEditor;
33+
2934
/**
3035
* Possible Subnetwork and ConnectedAP names which should be used in generated SCD in order a have global coherence
3136
* Configuration based on used framework can be used to externalize this datas
@@ -34,10 +39,6 @@ public class SclAutomationService {
3439
new SubNetworkTypeDTO("RSPACE_PROCESS_NETWORK", SubNetworkDTO.SubnetworkType.MMS.toString(), List.of("PROCESS_AP", "TOTO_AP_GE")),
3540
new SubNetworkTypeDTO("RSPACE_ADMIN_NETWORK", SubNetworkDTO.SubnetworkType.IP.toString(), List.of("ADMIN_AP", "TATA_AP_EFFACEC")));
3641

37-
private SclAutomationService() {
38-
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
39-
}
40-
4142
/**
4243
* Create an SCD file from specified parameters, it calls all functions defined in the process one by one, every step
4344
* return an SCD file which will be used by the next step.
@@ -47,15 +48,15 @@ private SclAutomationService() {
4748
* @return an SCD object
4849
* @throws ScdException
4950
*/
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());
51+
public SCL createSCD(@NonNull SCL ssd, @NonNull HeaderDTO headerDTO, List<SCL> stds) throws ScdException {
52+
SCL scd = sclEditor.initScl(headerDTO.getId(), headerDTO.getVersion(), headerDTO.getRevision());
5253
if (!headerDTO.getHistoryItems().isEmpty()) {
5354
HeaderDTO.HistoryItem hItem = headerDTO.getHistoryItems().get(0);
54-
SclService.addHistoryItem(scd, hItem.getWho(), hItem.getWhat(), hItem.getWhy());
55+
sclEditor.addHistoryItem(scd, hItem.getWho(), hItem.getWhat(), hItem.getWhy());
5556
}
56-
SubstationService.addSubstation(scd, ssd);
57-
SclService.importSTDElementsInSCD(scd, stds, SUB_NETWORK_TYPES);
58-
SclService.removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(scd);
57+
substationEditor.addSubstation(scd, ssd);
58+
sclEditor.importSTDElementsInSCD(scd, stds, SUB_NETWORK_TYPES);
59+
sclEditor.removeAllControlBlocksAndDatasetsAndExtRefSrcBindings(scd);
5960
return scd;
6061
}
6162
}

0 commit comments

Comments
 (0)