Skip to content

Commit 472cd9f

Browse files
author
Dennis Labordus
authored
Merge pull request #126 from com-pas/develop
Develop -> Main
2 parents 2d841e0 + dbdf572 commit 472cd9f

6 files changed

Lines changed: 56 additions & 54 deletions

File tree

MAPPING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ There is an IEC document describing the mapping, namely IEC/TS 62361-102, but no
5151
| List<*Switches*> | List<TConductingEquipment> | (2) |
5252
| List<cim:PowerTransformer> | List<TPowerTransformer> | |
5353

54-
(1): The ConnectivityNodes that are linked to the Bay thought the terminals of the switches of the Bay.
54+
(1): The ConnectivityNodes that are linked to the Bay thought the terminals of the switches of the Bay.
5555
(2): Switches in IEC CIM can be the following types, cim:Switch, cim:Breaker, cim:Disconnector, cim:LoadBreakSwitch and
5656
cim:ProtectedSwitch. These classes are all mapped in the same way on IEC 61850
5757

app/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SPDX-License-Identifier: Apache-2.0
1818
<packaging>jar</packaging>
1919

2020
<properties>
21-
<quarkus.platform.version>2.3.0.Final</quarkus.platform.version>
21+
<quarkus.platform.version>2.3.1.Final</quarkus.platform.version>
2222

2323
<quarkus.container-image.group>lfenergy</quarkus.container-image.group>
2424
<quarkus.container-image.name>compas-cim-mapping</quarkus.container-image.name>

service/src/main/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapper.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ protected abstract TVoltageLevel mapVoltageLevelToTVoltageLevel(CgmesVoltageLeve
8888
protected void afterVoltageLevelToTVoltageLevel(CgmesVoltageLevel cgmesVoltageLevel,
8989
@MappingTarget TVoltageLevel tVoltageLevel,
9090
@Context CimToSclMapperContext context) {
91+
// First we need to process the BusbarSections before the Bays.
92+
// This way the Connectivity Nodes from the BusbarSections are known to the Terminals in the Bay.
9193
context.getBusbarSectionsByEquipmentContainer(cgmesVoltageLevel.getId())
9294
.stream()
9395
.map(cgmesBusbarSection -> mapBusbarSectionBayToTBay(cgmesBusbarSection, cgmesVoltageLevel, tVoltageLevel, context))
@@ -116,7 +118,8 @@ protected void afterBusbarSectionBayToTBay(CgmesBusbarSection cgmesBusbarSection
116118
@MappingTarget TBay tBay,
117119
@Context CimToSclMapperContext context) {
118120
context.getConnectivityNodeByBusbarSection(cgmesBusbarSection.getId()).stream()
119-
.map(cn -> mapConnectivityNodeToTConnectivityNode(cn, context, false))
121+
.filter(cn -> !context.containsTConnectivityNode(cn.getId()))
122+
.map(cn -> mapConnectivityNodeToTConnectivityNode(cn, context))
120123
.forEach(tConnectivityNode -> tBay.getConnectivityNode().add(tConnectivityNode));
121124
}
122125

@@ -135,7 +138,8 @@ protected void afterBayToTBay(CgmesBay cgmesBay,
135138
// of a Conduction Equipment.
136139
context.getConnectivityNodeByBay(cgmesBay.getId())
137140
.stream()
138-
.map(cn -> mapConnectivityNodeToTConnectivityNode(cn, context, true))
141+
.filter(cn -> !context.containsTConnectivityNode(cn.getId()))
142+
.map(cn -> mapConnectivityNodeToTConnectivityNode(cn, context))
139143
.forEach(tConnectivityNode -> tBay.getConnectivityNode().add(tConnectivityNode));
140144

141145
// Now we can process the Conduction Equipment with their terminals.
@@ -199,19 +203,15 @@ protected abstract TTapChanger mapTapChangerToTTapChanger(CgmesTapChanger tapCha
199203

200204
@Mapping(target = "name", source = "nameOrId")
201205
protected abstract TConnectivityNode mapConnectivityNodeToTConnectivityNode(CgmesConnectivityNode cgmesConnectivityNode,
202-
@Context CimToSclMapperContext context,
203-
@Context boolean rememberConnectivityNode);
206+
@Context CimToSclMapperContext context);
204207

205208
@AfterMapping
206209
protected void afterConnectivityNodeToTConnectivityNode(CgmesConnectivityNode cgmesConnectivityNode,
207210
@MappingTarget TConnectivityNode tConnectivityNode,
208-
@Context CimToSclMapperContext context,
209-
@Context boolean rememberConnectivityNode) {
211+
@Context CimToSclMapperContext context) {
210212
var pathName = context.createPathName();
211213
tConnectivityNode.setPathName(pathName);
212-
if (rememberConnectivityNode) {
213-
context.saveTConnectivityNode(cgmesConnectivityNode.getId(), tConnectivityNode);
214-
}
214+
context.saveTConnectivityNode(cgmesConnectivityNode.getId(), tConnectivityNode);
215215
}
216216

217217
@Mapping(target = "name", source = "nameOrId")

service/src/main/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapperContext.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ public void saveTConnectivityNode(String id, TConnectivityNode tConnectivityNode
334334
connectivityNodeIdMap.put(id, tConnectivityNode);
335335
}
336336

337+
public boolean containsTConnectivityNode(String id) {
338+
return connectivityNodeIdMap.containsKey(id);
339+
}
340+
337341
public Optional<String> getPathnameFromConnectivityNode(String id) {
338342
var tConnectivityNode = connectivityNodeIdMap.get(id);
339343
if (tConnectivityNode != null) {

service/src/test/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapperContextTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,22 @@ void resetTConnectivityNodeMap_WhenCalledAfterRest_ThenPathNameOfCNCannotBeFound
441441
assertFalse(result.isPresent());
442442
}
443443

444+
@Test
445+
void containsTConnectivityNode_WhenCalledWithKnownId_ThenTrueReturned() {
446+
var knownCnId = "CN ID";
447+
448+
context.saveTConnectivityNode(knownCnId, new TConnectivityNode());
449+
context.saveTConnectivityNode("Other ID", new TConnectivityNode());
450+
assertTrue(context.containsTConnectivityNode(knownCnId));
451+
}
452+
453+
@Test
454+
void containsTConnectivityNode_WhenCalledWithUnknownId_ThenFalseReturned() {
455+
context.saveTConnectivityNode("CN ID", new TConnectivityNode());
456+
context.saveTConnectivityNode("Other ID", new TConnectivityNode());
457+
assertFalse(context.containsTConnectivityNode("Unknown ID"));
458+
}
459+
444460
@Test
445461
void getPathnameFromConnectivityNode_WhenCalledWithKnownId_ThenPathNameOfCNReturned() {
446462
var cnId = "CN ID";

service/src/test/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapperTest.java

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,15 @@ void map_WhenWithCimData_ThenSclMapped() throws IOException {
7575
// There is one busbarSection converted to a bay, this will be the first entry.
7676
var busbarSection = voltageLevel.getBay().get(0);
7777
assertBay(busbarSection, "BUSBAR10", 1, 0);
78+
assertConnectivityNode(busbarSection.getConnectivityNode().get(0), "CONNECTIVITY_NODE82",
79+
"_af9a4ae3-ba2e-4c34-8e47-5af894ee20f4/S1 380kV/BUSBAR10/CONNECTIVITY_NODE82");
80+
7881
// The others bay are actual bays from CIM.
7982
var bay = voltageLevel.getBay().get(1);
80-
assertBay(bay, "BAY_T4_2", 4, 3);
83+
assertBay(bay, "BAY_T4_2", 3, 3);
8184

82-
assertConnectivityNode(bay.getConnectivityNode().get(0));
85+
assertConnectivityNode(bay.getConnectivityNode().get(0), "CONNECTIVITY_NODE83",
86+
"_af9a4ae3-ba2e-4c34-8e47-5af894ee20f4/S1 380kV/BAY_T4_2/CONNECTIVITY_NODE83");
8387

8488
var conductingEquipment = bay.getConductingEquipment().get(0);
8589
assertConductingEquipment(conductingEquipment);
@@ -121,10 +125,10 @@ private void assertVoltageLevel(TVoltageLevel voltageLevel) {
121125
assertEquals("V", voltageLevel.getVoltage().getUnit());
122126
}
123127

124-
private void assertConnectivityNode(TConnectivityNode connectivityNode) {
128+
private void assertConnectivityNode(TConnectivityNode connectivityNode, String name, String pathName) {
125129
assertNotNull(connectivityNode);
126-
assertEquals("CONNECTIVITY_NODE82", connectivityNode.getName());
127-
assertEquals("_af9a4ae3-ba2e-4c34-8e47-5af894ee20f4/S1 380kV/BAY_T4_2/CONNECTIVITY_NODE82", connectivityNode.getPathName());
130+
assertEquals(name, connectivityNode.getName());
131+
assertEquals(pathName, connectivityNode.getPathName());
128132
}
129133

130134
private void assertConductingEquipment(TConductingEquipment conductingEquipment) {
@@ -195,41 +199,41 @@ void mapVoltageLevelToTVoltageLevel_WhenCalledWithVoltageLevel_ThenPropertiesMap
195199
}
196200

197201
@Test
198-
void mapBayToTBay_WhenCalledWithCgmesBay_ThenPropertiesMappedToTBay() {
202+
void mapBusbarSectionBayToTBay_WhenCalledWithCgmesBusbarSection_ThenPropertiesMappedToTBay() {
199203
var tVoltageLevel = mock(TVoltageLevel.class);
200204
var cgmesVoltageLevel = mock(CgmesVoltageLevel.class);
201-
var cgmesBay = mock(CgmesBay.class);
205+
var cgmesBusbarSection = mock(CgmesBusbarSection.class);
202206
var expectedName = "TheName";
203207

204-
when(cgmesBay.getNameOrId()).thenReturn(expectedName);
208+
when(cgmesBusbarSection.getNameOrId()).thenReturn(expectedName);
205209

206-
var sclBay = mapper.mapBayToTBay(cgmesBay, cgmesVoltageLevel, tVoltageLevel, context);
210+
var sclBay = mapper.mapBusbarSectionBayToTBay(cgmesBusbarSection, cgmesVoltageLevel, tVoltageLevel, context);
207211

208212
assertNotNull(sclBay);
209213
assertEquals(expectedName, sclBay.getName());
210-
verify(cgmesBay, times(3)).getId();
211-
verify(cgmesBay, times(1)).getNameOrId();
214+
verify(cgmesBusbarSection, times(1)).getId();
215+
verify(cgmesBusbarSection, times(1)).getNameOrId();
212216
verify(context, times(1)).addLast(sclBay);
213-
verifyNoMoreInteractions(cgmesBay);
217+
verifyNoMoreInteractions(cgmesBusbarSection);
214218
}
215219

216220
@Test
217-
void mapBusbarSectionBayToTBay_WhenCalledWithCgmesBusbarSection_ThenPropertiesMappedToTBay() {
221+
void mapBayToTBay_WhenCalledWithCgmesBay_ThenPropertiesMappedToTBay() {
218222
var tVoltageLevel = mock(TVoltageLevel.class);
219223
var cgmesVoltageLevel = mock(CgmesVoltageLevel.class);
220-
var cgmesBusbarSection = mock(CgmesBusbarSection.class);
224+
var cgmesBay = mock(CgmesBay.class);
221225
var expectedName = "TheName";
222226

223-
when(cgmesBusbarSection.getNameOrId()).thenReturn(expectedName);
227+
when(cgmesBay.getNameOrId()).thenReturn(expectedName);
224228

225-
var sclBay = mapper.mapBusbarSectionBayToTBay(cgmesBusbarSection, cgmesVoltageLevel, tVoltageLevel, context);
229+
var sclBay = mapper.mapBayToTBay(cgmesBay, cgmesVoltageLevel, tVoltageLevel, context);
226230

227231
assertNotNull(sclBay);
228232
assertEquals(expectedName, sclBay.getName());
229-
verify(cgmesBusbarSection, times(1)).getId();
230-
verify(cgmesBusbarSection, times(1)).getNameOrId();
233+
verify(cgmesBay, times(3)).getId();
234+
verify(cgmesBay, times(1)).getNameOrId();
231235
verify(context, times(1)).addLast(sclBay);
232-
verifyNoMoreInteractions(cgmesBusbarSection);
236+
verifyNoMoreInteractions(cgmesBay);
233237
}
234238

235239
@Test
@@ -289,7 +293,7 @@ void mapTapChangerToTTapChanger_WhenCalledWithCgmesTapChanger_ThenPropertiesMapp
289293
}
290294

291295
@Test
292-
void mapConnectivityNodeToTConnectivityNode_WhenCalledWithCgmesConnectivityNodeAndCacheble_ThenPropertiesMappedToTConnectivityNodeAndCached() {
296+
void mapConnectivityNodeToTConnectivityNode_WhenCalledWithCgmesConnectivityNode_ThenPropertiesMappedToTConnectivityNode() {
293297
var cgmesConnectivityNode = mock(CgmesConnectivityNode.class);
294298
var expectedId = "Id";
295299
var expectedName = "TheName";
@@ -299,7 +303,7 @@ void mapConnectivityNodeToTConnectivityNode_WhenCalledWithCgmesConnectivityNodeA
299303
when(cgmesConnectivityNode.getNameOrId()).thenReturn(expectedName);
300304
when(context.createPathName()).thenReturn(expectedPathName);
301305

302-
var sclConnectivityNode = mapper.mapConnectivityNodeToTConnectivityNode(cgmesConnectivityNode, context, true);
306+
var sclConnectivityNode = mapper.mapConnectivityNodeToTConnectivityNode(cgmesConnectivityNode, context);
303307

304308
assertNotNull(sclConnectivityNode);
305309
assertEquals(expectedName, sclConnectivityNode.getName());
@@ -311,28 +315,6 @@ void mapConnectivityNodeToTConnectivityNode_WhenCalledWithCgmesConnectivityNodeA
311315
verifyNoMoreInteractions(cgmesConnectivityNode);
312316
}
313317

314-
@Test
315-
void mapConnectivityNodeToTConnectivityNode_WhenCalledWithCgmesConnectivityNodeAndNotCacheble_ThenPropertiesMappedToTConnectivityNodeAndNotCached() {
316-
var cgmesConnectivityNode = mock(CgmesConnectivityNode.class);
317-
var expectedId = "Id";
318-
var expectedName = "TheName";
319-
var expectedPathName = "ThePathName";
320-
321-
when(cgmesConnectivityNode.getNameOrId()).thenReturn(expectedName);
322-
when(context.createPathName()).thenReturn(expectedPathName);
323-
324-
var sclConnectivityNode = mapper.mapConnectivityNodeToTConnectivityNode(cgmesConnectivityNode, context, false);
325-
326-
assertNotNull(sclConnectivityNode);
327-
assertEquals(expectedName, sclConnectivityNode.getName());
328-
assertEquals(expectedPathName, sclConnectivityNode.getPathName());
329-
verify(cgmesConnectivityNode, never()).getId();
330-
verify(cgmesConnectivityNode, times(1)).getNameOrId();
331-
verify(context, times(1)).addLast(sclConnectivityNode);
332-
verify(context, never()).saveTConnectivityNode(eq(expectedId), any(TConnectivityNode.class));
333-
verifyNoMoreInteractions(cgmesConnectivityNode);
334-
}
335-
336318
@Test
337319
void mapSwitchToTConductingEquipment_WhenCalledWithCgmesSwitchOtherType_ThenPropertiesMappedToTConductingEquipment() {
338320
var tVoltageLevel = mock(TVoltageLevel.class);

0 commit comments

Comments
 (0)