Skip to content

Commit dde7338

Browse files
authored
Merge pull request #89 from com-pas/feat/65-Automated-SCD-Creation-With-Substation
Feat/65 automated scd creation with substation
2 parents a61eb41 + a07cc89 commit dde7338

File tree

8 files changed

+244
-37
lines changed

8 files changed

+244
-37
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<module>sct-commons</module>
9090
<module>sct-coverage</module>
9191
<module>sct-data</module>
92+
<module>sct-app</module>
9293
</modules>
9394

9495
<build>

sct-app/pom.xml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- SPDX-FileCopyrightText: 2021 RTE FRANCE -->
3+
<!-- -->
4+
<!-- SPDX-License-Identifier: Apache-2.0 -->
5+
<project xmlns="http://maven.apache.org/POM/4.0.0"
6+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
8+
<modelVersion>4.0.0</modelVersion>
9+
10+
<parent>
11+
<groupId>org.lfenergy.compas</groupId>
12+
<artifactId>compas-sct</artifactId>
13+
<version>local-SNAPSHOT</version>
14+
</parent>
15+
16+
<groupId>org.lfenergy.compas</groupId>
17+
<artifactId>sct-app</artifactId>
18+
<version>local-SNAPSHOT</version>
19+
<name>SCT-APP</name>
20+
21+
22+
<properties>
23+
<sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.lfenergy.compas</groupId>
29+
<artifactId>sct-commons</artifactId>
30+
<version>${project.version}</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.lfenergy.compas</groupId>
34+
<artifactId>sct-data</artifactId>
35+
<version>${project.version}</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.lfenergy.compas</groupId>
39+
<artifactId>sct-commons</artifactId>
40+
<type>test-jar</type>
41+
<version>${project.version}</version>
42+
<scope>test</scope>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.projectlombok</groupId>
46+
<artifactId>lombok</artifactId>
47+
<optional>true</optional>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.junit.jupiter</groupId>
51+
<artifactId>junit-jupiter-api</artifactId>
52+
<scope>test</scope>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.junit.jupiter</groupId>
56+
<artifactId>junit-jupiter-engine</artifactId>
57+
<scope>test</scope>
58+
</dependency>
59+
</dependencies>
60+
<build>
61+
<plugins>
62+
<plugin>
63+
<groupId>org.apache.maven.plugins</groupId>
64+
<artifactId>maven-compiler-plugin</artifactId>
65+
<configuration>
66+
<source>11</source>
67+
<target>11</target>
68+
</configuration>
69+
</plugin>
70+
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-surefire-plugin</artifactId>
74+
</plugin>
75+
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-dependency-plugin</artifactId>
79+
<executions>
80+
<execution>
81+
<id>unpack</id>
82+
<phase>initialize</phase>
83+
<goals>
84+
<goal>unpack</goal>
85+
</goals>
86+
87+
<configuration>
88+
<artifactItems>
89+
<artifactItem>
90+
<groupId>org.lfenergy.compas.xsd</groupId>
91+
<artifactId>compas-scl-xsd</artifactId>
92+
<version>0.0.4</version>
93+
</artifactItem>
94+
</artifactItems>
95+
<outputDirectory>${project.build.directory}</outputDirectory>
96+
</configuration>
97+
</execution>
98+
</executions>
99+
</plugin>
100+
101+
</plugins>
102+
</build>
103+
</project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-FileCopyrightText: 2021 RTE FRANCE
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sct.app;
6+
7+
import lombok.NonNull;
8+
import lombok.extern.slf4j.Slf4j;
9+
import org.lfenergy.compas.scl2007b4.model.SCL;
10+
import org.lfenergy.compas.sct.commons.dto.HeaderDTO;
11+
import org.lfenergy.compas.sct.commons.exception.ScdException;
12+
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
13+
import org.lfenergy.compas.sct.commons.scl.SclService;
14+
15+
import java.util.Optional;
16+
17+
@Slf4j
18+
public class SclAutomationService {
19+
20+
private SclAutomationService(){throw new IllegalStateException("SclAutomationService class"); }
21+
22+
public static SclRootAdapter createSCD(@NonNull SCL ssd, @NonNull HeaderDTO headerDTO) throws ScdException {
23+
SclRootAdapter scdAdapter = SclService.initScl(Optional.ofNullable(headerDTO.getId()),
24+
headerDTO.getVersion(),headerDTO.getRevision());
25+
if(!headerDTO.getHistoryItems().isEmpty()) {
26+
headerDTO.getHistoryItems().forEach(hItem ->
27+
SclService.addHistoryItem(scdAdapter.getCurrentElem(), hItem.getWho(), hItem.getWhat(), hItem.getWhy()));
28+
}
29+
SclService.addSubstation(scdAdapter.getCurrentElem(), ssd);
30+
return scdAdapter;
31+
}
32+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- SPDX-FileCopyrightText: 2021 RTE FRANCE -->
3+
<!-- -->
4+
<!-- SPDX-License-Identifier: Apache-2.0 -->
5+
6+
<configuration>
7+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
8+
<layout class="ch.qos.logback.classic.PatternLayout">
9+
<Pattern>
10+
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
11+
</Pattern>
12+
</layout>
13+
</appender>
14+
15+
<logger name="org.lfenergy.compas.sct.app" level="trace" additivity="false">
16+
<appender-ref ref="CONSOLE"/>
17+
</logger>
18+
19+
<root level="error">
20+
<appender-ref ref="CONSOLE"/>
21+
</root>
22+
</configuration>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// SPDX-FileCopyrightText: 2021 RTE FRANCE
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sct.app;
6+
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.Test;
9+
import org.lfenergy.compas.scl2007b4.model.SCL;
10+
import org.lfenergy.compas.sct.commons.dto.HeaderDTO;
11+
import org.lfenergy.compas.sct.commons.exception.ScdException;
12+
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
13+
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller;
14+
15+
import java.util.Arrays;
16+
17+
import static org.junit.jupiter.api.Assertions.*;
18+
19+
class SclAutomationServiceTest {
20+
21+
private HeaderDTO headerDTO;
22+
23+
@BeforeEach
24+
void init(){
25+
headerDTO = new HeaderDTO();
26+
headerDTO.setRevision("hRevision");
27+
headerDTO.setVersion("hVersion");
28+
}
29+
30+
@Test
31+
void createSCD() throws Exception {
32+
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd.xml");
33+
SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO);
34+
assertNotNull(expectedSCD.getCurrentElem().getHeader().getId());
35+
assertNull(expectedSCD.getCurrentElem().getHeader().getHistory());
36+
assertEquals(1, expectedSCD.getCurrentElem().getSubstation().size());
37+
}
38+
39+
@Test
40+
void createSCD_With_HItem() throws Exception {
41+
HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem();
42+
historyItem.setWhat("what");
43+
historyItem.setWho("me");
44+
historyItem.setWhy("because");
45+
headerDTO.getHistoryItems().add(historyItem);
46+
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd.xml");
47+
SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO);
48+
assertNotNull(expectedSCD.getCurrentElem().getHeader().getId());
49+
assertEquals(1 ,expectedSCD.getCurrentElem().getHeader().getHistory().getHitem().size());
50+
assertEquals(1, expectedSCD.getCurrentElem().getSubstation().size());
51+
}
52+
53+
@Test
54+
void createSCD_With_HItems() throws Exception {
55+
HeaderDTO.HistoryItem historyItem = new HeaderDTO.HistoryItem();
56+
historyItem.setWhat("what");
57+
historyItem.setWho("me");
58+
historyItem.setWhy("because");
59+
HeaderDTO.HistoryItem historyItemBis = new HeaderDTO.HistoryItem();
60+
historyItemBis.setWhat("what Bis");
61+
historyItemBis.setWho("me bis");
62+
historyItemBis.setWhy("because bis");
63+
headerDTO.getHistoryItems().addAll(Arrays.asList(historyItem, historyItemBis));
64+
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd.xml");
65+
SclRootAdapter expectedSCD = SclAutomationService.createSCD(ssd, headerDTO);
66+
assertNotNull(expectedSCD.getCurrentElem().getHeader().getId());
67+
assertEquals(2 ,expectedSCD.getCurrentElem().getHeader().getHistory().getHitem().size());
68+
}
69+
70+
71+
@Test
72+
void createSCD_SSD_Without_Substation() throws Exception {
73+
SCL ssd = SclTestMarshaller.getSCLFromFile("/scd-substation-import-ssd/ssd_without_substations.xml");
74+
assertThrows(ScdException.class,
75+
() -> SclAutomationService.createSCD(ssd, headerDTO) );
76+
}
77+
}

sct-commons/pom.xml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,26 +146,18 @@
146146
</execution>
147147
</executions>
148148
</plugin>
149-
150149
<plugin>
151-
<groupId>org.jacoco</groupId>
152-
<artifactId>jacoco-maven-plugin</artifactId>
150+
<groupId>org.apache.maven.plugins</groupId>
151+
<artifactId>maven-jar-plugin</artifactId>
153152
<executions>
154153
<execution>
155-
<id>default-prepare-agent</id>
156154
<goals>
157-
<goal>prepare-agent</goal>
158-
</goals>
159-
</execution>
160-
<execution>
161-
<id>report</id>
162-
<phase>test</phase>
163-
<goals>
164-
<goal>report</goal>
155+
<goal>test-jar</goal>
165156
</goals>
166157
</execution>
167158
</executions>
168159
</plugin>
160+
169161
</plugins>
170162
</build>
171163
</project>

sct-coverage/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
<artifactId>sct-data</artifactId>
3333
<version>${project.version}</version>
3434
</dependency>
35+
<dependency>
36+
<groupId>org.lfenergy.compas</groupId>
37+
<artifactId>sct-app</artifactId>
38+
<version>${project.version}</version>
39+
</dependency>
3540
</dependencies>
3641
<build>
3742
<plugins>

sct-data/pom.xml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,4 @@
3939
<scope>test</scope>
4040
</dependency>
4141
</dependencies>
42-
43-
<build>
44-
<plugins>
45-
<plugin>
46-
<groupId>org.jacoco</groupId>
47-
<artifactId>jacoco-maven-plugin</artifactId>
48-
<executions>
49-
<execution>
50-
<id>default-prepare-agent</id>
51-
<goals>
52-
<goal>prepare-agent</goal>
53-
</goals>
54-
</execution>
55-
<execution>
56-
<id>report</id>
57-
<phase>test</phase>
58-
<goals>
59-
<goal>report</goal>
60-
</goals>
61-
</execution>
62-
</executions>
63-
</plugin>
64-
</plugins>
65-
</build>
66-
6742
</project>

0 commit comments

Comments
 (0)