From 9340fadc25dd7cdd54378520bf40a1a9cc3cf6f8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Oct 2021 15:16:26 +0000 Subject: [PATCH 1/2] Bump quarkus.platform.version from 2.3.0.Final to 2.3.1.Final Bumps `quarkus.platform.version` from 2.3.0.Final to 2.3.1.Final. Updates `quarkus-universe-bom` from 2.3.0.Final to 2.3.1.Final - [Release notes](https://github.com/quarkusio/quarkus-platform/releases) - [Commits](https://github.com/quarkusio/quarkus-platform/compare/2.3.0.Final...2.3.1.Final) Updates `quarkus-maven-plugin` from 2.3.0.Final to 2.3.1.Final --- updated-dependencies: - dependency-name: io.quarkus:quarkus-universe-bom dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: io.quarkus:quarkus-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- app/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/pom.xml b/app/pom.xml index b8f2e6e..73f9534 100644 --- a/app/pom.xml +++ b/app/pom.xml @@ -18,7 +18,7 @@ SPDX-License-Identifier: Apache-2.0 jar - 2.3.0.Final + 2.3.1.Final lfenergy compas-cim-mapping From 3491ed58289bc45f6d164535a050d30fb22165bc Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Mon, 25 Oct 2021 15:00:19 +0200 Subject: [PATCH 2/2] Fixed bug with ConnectivityNodes and BusbarSections. Signed-off-by: Dennis Labordus --- MAPPING.md | 2 +- .../cim/mapping/mapper/CimToSclMapper.java | 18 ++--- .../mapping/mapper/CimToSclMapperContext.java | 4 ++ .../mapper/CimToSclMapperContextTest.java | 16 +++++ .../mapping/mapper/CimToSclMapperTest.java | 68 +++++++------------ 5 files changed, 55 insertions(+), 53 deletions(-) diff --git a/MAPPING.md b/MAPPING.md index 8933175..ab23ef0 100644 --- a/MAPPING.md +++ b/MAPPING.md @@ -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 diff --git a/service/src/main/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapper.java b/service/src/main/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapper.java index caeceba..201b47e 100644 --- a/service/src/main/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapper.java +++ b/service/src/main/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapper.java @@ -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)) @@ -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)); } @@ -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. @@ -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") diff --git a/service/src/main/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapperContext.java b/service/src/main/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapperContext.java index 0d20337..a2b029d 100644 --- a/service/src/main/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapperContext.java +++ b/service/src/main/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapperContext.java @@ -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 getPathnameFromConnectivityNode(String id) { var tConnectivityNode = connectivityNodeIdMap.get(id); if (tConnectivityNode != null) { diff --git a/service/src/test/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapperContextTest.java b/service/src/test/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapperContextTest.java index 63d406b..36982e8 100644 --- a/service/src/test/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapperContextTest.java +++ b/service/src/test/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapperContextTest.java @@ -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"; diff --git a/service/src/test/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapperTest.java b/service/src/test/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapperTest.java index b2a6653..ab20694 100644 --- a/service/src/test/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapperTest.java +++ b/service/src/test/java/org/lfenergy/compas/cim/mapping/mapper/CimToSclMapperTest.java @@ -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); @@ -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) { @@ -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 @@ -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"; @@ -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()); @@ -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);