Skip to content

Commit

Permalink
Merge pull request #126 from com-pas/develop
Browse files Browse the repository at this point in the history
Develop -> Main
  • Loading branch information
Dennis Labordus authored Oct 26, 2021
2 parents 2d841e0 + dbdf572 commit 472cd9f
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 54 deletions.
2 changes: 1 addition & 1 deletion MAPPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ There is an IEC document describing the mapping, namely IEC/TS 62361-102, but no
| List<*Switches*> | List<TConductingEquipment> | (2) |
| List<cim:PowerTransformer> | List<TPowerTransformer> | |

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

Expand Down
2 changes: 1 addition & 1 deletion app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SPDX-License-Identifier: Apache-2.0
<packaging>jar</packaging>

<properties>
<quarkus.platform.version>2.3.0.Final</quarkus.platform.version>
<quarkus.platform.version>2.3.1.Final</quarkus.platform.version>

<quarkus.container-image.group>lfenergy</quarkus.container-image.group>
<quarkus.container-image.name>compas-cim-mapping</quarkus.container-image.name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ protected abstract TVoltageLevel mapVoltageLevelToTVoltageLevel(CgmesVoltageLeve
protected void afterVoltageLevelToTVoltageLevel(CgmesVoltageLevel cgmesVoltageLevel,
@MappingTarget TVoltageLevel tVoltageLevel,
@Context CimToSclMapperContext context) {
// First we need to process the BusbarSections before the Bays.
// This way the Connectivity Nodes from the BusbarSections are known to the Terminals in the Bay.
context.getBusbarSectionsByEquipmentContainer(cgmesVoltageLevel.getId())
.stream()
.map(cgmesBusbarSection -> mapBusbarSectionBayToTBay(cgmesBusbarSection, cgmesVoltageLevel, tVoltageLevel, context))
Expand Down Expand Up @@ -116,7 +118,8 @@ protected void afterBusbarSectionBayToTBay(CgmesBusbarSection cgmesBusbarSection
@MappingTarget TBay tBay,
@Context CimToSclMapperContext context) {
context.getConnectivityNodeByBusbarSection(cgmesBusbarSection.getId()).stream()
.map(cn -> mapConnectivityNodeToTConnectivityNode(cn, context, false))
.filter(cn -> !context.containsTConnectivityNode(cn.getId()))
.map(cn -> mapConnectivityNodeToTConnectivityNode(cn, context))
.forEach(tConnectivityNode -> tBay.getConnectivityNode().add(tConnectivityNode));
}

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

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

@Mapping(target = "name", source = "nameOrId")
protected abstract TConnectivityNode mapConnectivityNodeToTConnectivityNode(CgmesConnectivityNode cgmesConnectivityNode,
@Context CimToSclMapperContext context,
@Context boolean rememberConnectivityNode);
@Context CimToSclMapperContext context);

@AfterMapping
protected void afterConnectivityNodeToTConnectivityNode(CgmesConnectivityNode cgmesConnectivityNode,
@MappingTarget TConnectivityNode tConnectivityNode,
@Context CimToSclMapperContext context,
@Context boolean rememberConnectivityNode) {
@Context CimToSclMapperContext context) {
var pathName = context.createPathName();
tConnectivityNode.setPathName(pathName);
if (rememberConnectivityNode) {
context.saveTConnectivityNode(cgmesConnectivityNode.getId(), tConnectivityNode);
}
context.saveTConnectivityNode(cgmesConnectivityNode.getId(), tConnectivityNode);
}

@Mapping(target = "name", source = "nameOrId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ public void saveTConnectivityNode(String id, TConnectivityNode tConnectivityNode
connectivityNodeIdMap.put(id, tConnectivityNode);
}

public boolean containsTConnectivityNode(String id) {
return connectivityNodeIdMap.containsKey(id);
}

public Optional<String> getPathnameFromConnectivityNode(String id) {
var tConnectivityNode = connectivityNodeIdMap.get(id);
if (tConnectivityNode != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,22 @@ void resetTConnectivityNodeMap_WhenCalledAfterRest_ThenPathNameOfCNCannotBeFound
assertFalse(result.isPresent());
}

@Test
void containsTConnectivityNode_WhenCalledWithKnownId_ThenTrueReturned() {
var knownCnId = "CN ID";

context.saveTConnectivityNode(knownCnId, new TConnectivityNode());
context.saveTConnectivityNode("Other ID", new TConnectivityNode());
assertTrue(context.containsTConnectivityNode(knownCnId));
}

@Test
void containsTConnectivityNode_WhenCalledWithUnknownId_ThenFalseReturned() {
context.saveTConnectivityNode("CN ID", new TConnectivityNode());
context.saveTConnectivityNode("Other ID", new TConnectivityNode());
assertFalse(context.containsTConnectivityNode("Unknown ID"));
}

@Test
void getPathnameFromConnectivityNode_WhenCalledWithKnownId_ThenPathNameOfCNReturned() {
var cnId = "CN ID";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,15 @@ void map_WhenWithCimData_ThenSclMapped() throws IOException {
// There is one busbarSection converted to a bay, this will be the first entry.
var busbarSection = voltageLevel.getBay().get(0);
assertBay(busbarSection, "BUSBAR10", 1, 0);
assertConnectivityNode(busbarSection.getConnectivityNode().get(0), "CONNECTIVITY_NODE82",
"_af9a4ae3-ba2e-4c34-8e47-5af894ee20f4/S1 380kV/BUSBAR10/CONNECTIVITY_NODE82");

// The others bay are actual bays from CIM.
var bay = voltageLevel.getBay().get(1);
assertBay(bay, "BAY_T4_2", 4, 3);
assertBay(bay, "BAY_T4_2", 3, 3);

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

var conductingEquipment = bay.getConductingEquipment().get(0);
assertConductingEquipment(conductingEquipment);
Expand Down Expand Up @@ -121,10 +125,10 @@ private void assertVoltageLevel(TVoltageLevel voltageLevel) {
assertEquals("V", voltageLevel.getVoltage().getUnit());
}

private void assertConnectivityNode(TConnectivityNode connectivityNode) {
private void assertConnectivityNode(TConnectivityNode connectivityNode, String name, String pathName) {
assertNotNull(connectivityNode);
assertEquals("CONNECTIVITY_NODE82", connectivityNode.getName());
assertEquals("_af9a4ae3-ba2e-4c34-8e47-5af894ee20f4/S1 380kV/BAY_T4_2/CONNECTIVITY_NODE82", connectivityNode.getPathName());
assertEquals(name, connectivityNode.getName());
assertEquals(pathName, connectivityNode.getPathName());
}

private void assertConductingEquipment(TConductingEquipment conductingEquipment) {
Expand Down Expand Up @@ -195,41 +199,41 @@ void mapVoltageLevelToTVoltageLevel_WhenCalledWithVoltageLevel_ThenPropertiesMap
}

@Test
void mapBayToTBay_WhenCalledWithCgmesBay_ThenPropertiesMappedToTBay() {
void mapBusbarSectionBayToTBay_WhenCalledWithCgmesBusbarSection_ThenPropertiesMappedToTBay() {
var tVoltageLevel = mock(TVoltageLevel.class);
var cgmesVoltageLevel = mock(CgmesVoltageLevel.class);
var cgmesBay = mock(CgmesBay.class);
var cgmesBusbarSection = mock(CgmesBusbarSection.class);
var expectedName = "TheName";

when(cgmesBay.getNameOrId()).thenReturn(expectedName);
when(cgmesBusbarSection.getNameOrId()).thenReturn(expectedName);

var sclBay = mapper.mapBayToTBay(cgmesBay, cgmesVoltageLevel, tVoltageLevel, context);
var sclBay = mapper.mapBusbarSectionBayToTBay(cgmesBusbarSection, cgmesVoltageLevel, tVoltageLevel, context);

assertNotNull(sclBay);
assertEquals(expectedName, sclBay.getName());
verify(cgmesBay, times(3)).getId();
verify(cgmesBay, times(1)).getNameOrId();
verify(cgmesBusbarSection, times(1)).getId();
verify(cgmesBusbarSection, times(1)).getNameOrId();
verify(context, times(1)).addLast(sclBay);
verifyNoMoreInteractions(cgmesBay);
verifyNoMoreInteractions(cgmesBusbarSection);
}

@Test
void mapBusbarSectionBayToTBay_WhenCalledWithCgmesBusbarSection_ThenPropertiesMappedToTBay() {
void mapBayToTBay_WhenCalledWithCgmesBay_ThenPropertiesMappedToTBay() {
var tVoltageLevel = mock(TVoltageLevel.class);
var cgmesVoltageLevel = mock(CgmesVoltageLevel.class);
var cgmesBusbarSection = mock(CgmesBusbarSection.class);
var cgmesBay = mock(CgmesBay.class);
var expectedName = "TheName";

when(cgmesBusbarSection.getNameOrId()).thenReturn(expectedName);
when(cgmesBay.getNameOrId()).thenReturn(expectedName);

var sclBay = mapper.mapBusbarSectionBayToTBay(cgmesBusbarSection, cgmesVoltageLevel, tVoltageLevel, context);
var sclBay = mapper.mapBayToTBay(cgmesBay, cgmesVoltageLevel, tVoltageLevel, context);

assertNotNull(sclBay);
assertEquals(expectedName, sclBay.getName());
verify(cgmesBusbarSection, times(1)).getId();
verify(cgmesBusbarSection, times(1)).getNameOrId();
verify(cgmesBay, times(3)).getId();
verify(cgmesBay, times(1)).getNameOrId();
verify(context, times(1)).addLast(sclBay);
verifyNoMoreInteractions(cgmesBusbarSection);
verifyNoMoreInteractions(cgmesBay);
}

@Test
Expand Down Expand Up @@ -289,7 +293,7 @@ void mapTapChangerToTTapChanger_WhenCalledWithCgmesTapChanger_ThenPropertiesMapp
}

@Test
void mapConnectivityNodeToTConnectivityNode_WhenCalledWithCgmesConnectivityNodeAndCacheble_ThenPropertiesMappedToTConnectivityNodeAndCached() {
void mapConnectivityNodeToTConnectivityNode_WhenCalledWithCgmesConnectivityNode_ThenPropertiesMappedToTConnectivityNode() {
var cgmesConnectivityNode = mock(CgmesConnectivityNode.class);
var expectedId = "Id";
var expectedName = "TheName";
Expand All @@ -299,7 +303,7 @@ void mapConnectivityNodeToTConnectivityNode_WhenCalledWithCgmesConnectivityNodeA
when(cgmesConnectivityNode.getNameOrId()).thenReturn(expectedName);
when(context.createPathName()).thenReturn(expectedPathName);

var sclConnectivityNode = mapper.mapConnectivityNodeToTConnectivityNode(cgmesConnectivityNode, context, true);
var sclConnectivityNode = mapper.mapConnectivityNodeToTConnectivityNode(cgmesConnectivityNode, context);

assertNotNull(sclConnectivityNode);
assertEquals(expectedName, sclConnectivityNode.getName());
Expand All @@ -311,28 +315,6 @@ void mapConnectivityNodeToTConnectivityNode_WhenCalledWithCgmesConnectivityNodeA
verifyNoMoreInteractions(cgmesConnectivityNode);
}

@Test
void mapConnectivityNodeToTConnectivityNode_WhenCalledWithCgmesConnectivityNodeAndNotCacheble_ThenPropertiesMappedToTConnectivityNodeAndNotCached() {
var cgmesConnectivityNode = mock(CgmesConnectivityNode.class);
var expectedId = "Id";
var expectedName = "TheName";
var expectedPathName = "ThePathName";

when(cgmesConnectivityNode.getNameOrId()).thenReturn(expectedName);
when(context.createPathName()).thenReturn(expectedPathName);

var sclConnectivityNode = mapper.mapConnectivityNodeToTConnectivityNode(cgmesConnectivityNode, context, false);

assertNotNull(sclConnectivityNode);
assertEquals(expectedName, sclConnectivityNode.getName());
assertEquals(expectedPathName, sclConnectivityNode.getPathName());
verify(cgmesConnectivityNode, never()).getId();
verify(cgmesConnectivityNode, times(1)).getNameOrId();
verify(context, times(1)).addLast(sclConnectivityNode);
verify(context, never()).saveTConnectivityNode(eq(expectedId), any(TConnectivityNode.class));
verifyNoMoreInteractions(cgmesConnectivityNode);
}

@Test
void mapSwitchToTConductingEquipment_WhenCalledWithCgmesSwitchOtherType_ThenPropertiesMappedToTConductingEquipment() {
var tVoltageLevel = mock(TVoltageLevel.class);
Expand Down

0 comments on commit 472cd9f

Please sign in to comment.