Skip to content

Commit efe2583

Browse files
author
Dennis Labordus
authored
Merge pull request #51 from com-pas/develop
Create new release with library updates and bugfixes
2 parents 626a60d + 75e770f commit efe2583

File tree

16 files changed

+140
-217
lines changed

16 files changed

+140
-217
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ SPDX-License-Identifier: Apache-2.0
2626

2727
<compas.core.version>0.7.0</compas.core.version>
2828

29-
<quarkus.platform.version>2.6.2.Final</quarkus.platform.version>
30-
<slf4j.version>1.7.33</slf4j.version>
29+
<quarkus.platform.version>2.7.0.Final</quarkus.platform.version>
30+
<slf4j.version>1.7.35</slf4j.version>
3131
<powsybl.sld.version>2.7.0</powsybl.sld.version>
3232
<gson.version>2.8.9</gson.version>
3333
<openpojo.version>0.9.1</openpojo.version>

service/src/main/java/org/lfenergy/compas/scl/auto/alignment/model/AbstractGenericEntity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ public P getParent() {
4141
return parent;
4242
}
4343

44+
public long getCoordinate(String fieldName) {
45+
var value = element.getAttributeNS(SCLXY_NS_URI, fieldName);
46+
if (!value.isBlank()) {
47+
return Long.parseLong(value);
48+
}
49+
return 0;
50+
}
51+
4452
public void setXYCoordinates(long x, long y) {
4553
element.setAttributeNS(SCLXY_NS_URI, SCLXY_PREFIX + ":x", String.valueOf(x));
4654
element.setAttributeNS(SCLXY_NS_URI, SCLXY_PREFIX + ":y", String.valueOf(y));

service/src/main/java/org/lfenergy/compas/scl/auto/alignment/model/GenericBay.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.util.List;
99
import java.util.stream.Collectors;
10+
import java.util.stream.IntStream;
1011

1112
public class GenericBay extends AbstractGenericNameEntity<GenericVoltageLevel> {
1213
private List<GenericConnectivityNode> connectivityNodes;
@@ -17,7 +18,15 @@ public GenericBay(GenericVoltageLevel parent, Element element) {
1718
}
1819

1920
public boolean isBusbar() {
20-
return getConnectivityNodes().size() == 1;
21+
return getConnectivityNodes().size() == 1 && getNrOfChilderen() == 1;
22+
}
23+
24+
private long getNrOfChilderen() {
25+
var nodeList = getElement().getChildNodes();
26+
return IntStream.range(0, nodeList.getLength())
27+
.mapToObj(nodeList::item)
28+
.filter(Element.class::isInstance)
29+
.count();
2130
}
2231

2332
public List<GenericConnectivityNode> getConnectivityNodes() {

service/src/main/java/org/lfenergy/compas/scl/auto/alignment/model/GenericSubstation.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,4 @@ public Optional<GenericVoltageLevel> getVoltageLevel(String name) {
6464
}
6565
return Optional.empty();
6666
}
67-
68-
public Optional<GenericVoltageLevel> getVoltageLevelByFullName(String fullName) {
69-
if (StringUtils.isNotBlank(fullName)) {
70-
return getVoltageLevels().stream()
71-
.filter(voltageLevel -> fullName.equals(voltageLevel.getFullName()))
72-
.findFirst();
73-
}
74-
return Optional.empty();
75-
}
7667
}

service/src/main/java/org/lfenergy/compas/scl/auto/alignment/model/GenericVoltageLevel.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
// SPDX-License-Identifier: Apache-2.0
44
package org.lfenergy.compas.scl.auto.alignment.model;
55

6-
import org.apache.commons.lang3.StringUtils;
76
import org.lfenergy.compas.scl.auto.alignment.exception.SclAutoAlignmentException;
87
import org.w3c.dom.Element;
98

109
import java.util.List;
11-
import java.util.Optional;
1210
import java.util.stream.Collectors;
1311

1412
import static org.lfenergy.compas.scl.auto.alignment.exception.SclAutoAlignmentErrorCode.NO_VOLTAGE_FOUND_ERROR_CODE;
@@ -36,25 +34,4 @@ public List<GenericBay> getBays() {
3634
}
3735
return bays;
3836
}
39-
40-
public Optional<GenericBay> getBusbarByFullName(String fullName) {
41-
if (StringUtils.isNotBlank(fullName)) {
42-
return getBays().stream()
43-
.filter(GenericBay::isBusbar)
44-
.filter(busbar -> fullName.equals(busbar.getFullName()))
45-
.findFirst();
46-
}
47-
return Optional.empty();
48-
}
49-
50-
public Optional<GenericConductingEquipment> getConductingEquipmentByFullName(String fullName) {
51-
if (StringUtils.isNotBlank(fullName)) {
52-
return getBays().stream()
53-
.map(GenericBay::getConductingEquipments)
54-
.flatMap(List::stream)
55-
.filter(conductingEquipment -> fullName.equals(conductingEquipment.getFullName()))
56-
.findFirst();
57-
}
58-
return Optional.empty();
59-
}
6037
}

service/src/main/java/org/lfenergy/compas/scl/auto/alignment/service/SclAutoAlignmentEnricher.java

Lines changed: 82 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
// SPDX-License-Identifier: Apache-2.0
44
package org.lfenergy.compas.scl.auto.alignment.service;
55

6+
import com.google.gson.JsonArray;
7+
import com.google.gson.JsonElement;
68
import com.google.gson.JsonObject;
79
import com.google.gson.JsonParser;
8-
import org.lfenergy.compas.scl.auto.alignment.model.GenericSCL;
9-
import org.lfenergy.compas.scl.auto.alignment.model.GenericSubstation;
10-
import org.lfenergy.compas.scl.auto.alignment.model.GenericVoltageLevel;
10+
import org.lfenergy.compas.scl.auto.alignment.model.*;
1111

12-
import java.util.concurrent.atomic.AtomicLong;
12+
import java.util.Optional;
13+
import java.util.stream.StreamSupport;
1314

1415
import static org.lfenergy.compas.scl.auto.alignment.common.CommonUtil.cleanSXYDeclarationAndAttributes;
1516

@@ -32,56 +33,100 @@ public void enrich() {
3233

3334
// Next process the VoltageLevels.
3435
if (jsonSubstation.has("voltageLevels")) {
35-
jsonSubstation.getAsJsonArray("voltageLevels")
36-
.forEach(jsonVoltageLevel -> enrichVoltageLevel(substation, jsonVoltageLevel.getAsJsonObject()));
36+
JsonArray jsonNodes = jsonSubstation.getAsJsonArray("voltageLevels");
37+
substation.getVoltageLevels()
38+
.forEach(voltageLevel -> enrichVoltageLevel(jsonNodes, voltageLevel));
3739
}
3840

39-
AtomicLong pwtCoordinate = new AtomicLong(1);
40-
substation.getPowerTransformers().forEach(powerTransformer ->
41-
powerTransformer.setXYCoordinates(pwtCoordinate.get(), pwtCoordinate.getAndIncrement()));
41+
if (jsonSubstation.has("multitermNodes")) {
42+
JsonArray jsonNodes = jsonSubstation.getAsJsonArray("multitermNodes");
43+
substation.getPowerTransformers()
44+
.forEach(powerTransformer -> enrichPowerTransformer(jsonNodes, powerTransformer));
45+
}
4246
});
4347
}
4448

45-
private void enrichVoltageLevel(GenericSubstation substation, JsonObject jsonVoltageLevel) {
46-
var voltageLevelFullName = jsonVoltageLevel.get("voltageLevelInfos").getAsJsonObject().get("id").getAsString();
47-
var sclVoltageLevel = substation.getVoltageLevelByFullName(voltageLevelFullName);
48-
sclVoltageLevel.ifPresent(voltageLevel -> {
49-
voltageLevel.setXYCoordinates(getCoordinate(jsonVoltageLevel, "x"),
50-
getCoordinate(jsonVoltageLevel, "y"));
49+
private void enrichPowerTransformer(JsonArray jsonNodes, GenericPowerTransformer powerTransformer) {
50+
var jsonObject = findNode(jsonNodes, powerTransformer.getFullName());
51+
jsonObject.ifPresent(jsonPowerTransformer ->
52+
powerTransformer.setXYCoordinates(
53+
getCoordinate(jsonPowerTransformer, "x"),
54+
getCoordinate(jsonPowerTransformer, "y")));
55+
}
5156

52-
AtomicLong bayXCoordinate = new AtomicLong(1);
53-
voltageLevel.getBays()
54-
.stream()
55-
.filter(bay -> !bay.isBusbar())
56-
.forEach(bay -> bay.setXYCoordinates(bayXCoordinate.getAndIncrement(), 1));
57+
private void enrichVoltageLevel(JsonArray jsonNodes, GenericVoltageLevel voltageLevel) {
58+
var jsonObject = findVoltageLevelNode(jsonNodes, voltageLevel.getFullName());
59+
jsonObject.ifPresent(jsonVoltageLevel -> {
60+
voltageLevel.setXYCoordinates(
61+
getCoordinate(jsonVoltageLevel, "x"),
62+
getCoordinate(jsonVoltageLevel, "y"));
5763

5864
if (jsonVoltageLevel.has("nodes")) {
59-
jsonVoltageLevel.getAsJsonArray("nodes")
60-
.forEach(jsonNode -> {
61-
var type = jsonNode.getAsJsonObject().get("type").getAsString();
62-
if ("BUS".equals(type)) {
63-
enrichBusbar(voltageLevel, jsonNode.getAsJsonObject());
65+
JsonArray jsonSubNodes = jsonVoltageLevel.getAsJsonArray("nodes");
66+
voltageLevel.getBays()
67+
.forEach(bay -> {
68+
if (bay.isBusbar()) {
69+
enrichBusbar(jsonSubNodes, bay);
6470
} else {
65-
enrichConductingEquipment(voltageLevel, jsonNode.getAsJsonObject());
71+
enrichBay(jsonSubNodes, bay);
6672
}
6773
});
6874
}
6975
});
7076
}
7177

72-
private void enrichBusbar(GenericVoltageLevel voltageLevel, JsonObject jsonBusbar) {
73-
var fullName = jsonBusbar.get("id").getAsString();
74-
var sclBusbar = voltageLevel.getBusbarByFullName(fullName);
75-
sclBusbar.ifPresent(busbar ->
76-
busbar.setXYCoordinates(getCoordinate(jsonBusbar, "x"), getCoordinate(jsonBusbar, "y")));
78+
private Optional<JsonObject> findVoltageLevelNode(JsonArray jsonNodes, String fullName) {
79+
return StreamSupport.stream(jsonNodes.spliterator(), false)
80+
.map(JsonElement::getAsJsonObject)
81+
.filter(jsonObject -> fullName.equals(jsonObject.get("voltageLevelInfos").getAsJsonObject().get("id").getAsString()))
82+
.findFirst();
83+
}
84+
85+
private void enrichBusbar(JsonArray jsonNodes, GenericBay busbar) {
86+
var jsonObject = findNode(jsonNodes, busbar.getFullName());
87+
jsonObject.ifPresent(jsonBusbar ->
88+
busbar.setXYCoordinates(
89+
getCoordinate(jsonBusbar, "x"),
90+
getCoordinate(jsonBusbar, "y")));
91+
}
92+
93+
private void enrichBay(JsonArray jsonNodes, GenericBay bay) {
94+
var xCoordinate = getMinimumCoordinate(jsonNodes, bay, "x");
95+
var yCoordinate = getMinimumCoordinate(jsonNodes, bay, "y");
96+
bay.setXYCoordinates(xCoordinate, yCoordinate);
97+
98+
bay.getConductingEquipments()
99+
.forEach(conductingEquipment -> enrichConductingEquipment(jsonNodes, bay, conductingEquipment));
100+
}
101+
102+
private void enrichConductingEquipment(JsonArray jsonNodes, GenericBay bay, GenericConductingEquipment conductingEquipment) {
103+
var jsonObject = findNode(jsonNodes, conductingEquipment.getFullName());
104+
jsonObject.ifPresent(jsonConductingEquipment ->
105+
conductingEquipment.setXYCoordinates(
106+
getCoordinateForConductingEquipment(jsonConductingEquipment, bay, "x"),
107+
getCoordinateForConductingEquipment(jsonConductingEquipment, bay, "y")));
108+
}
109+
110+
private long getMinimumCoordinate(JsonArray jsonNodes, GenericBay bay, String fieldName) {
111+
return bay.getConductingEquipments()
112+
.stream()
113+
.map(conductingEquipment -> findNode(jsonNodes, conductingEquipment.getFullName()))
114+
.filter(Optional::isPresent)
115+
.flatMap(Optional::stream)
116+
.mapToLong(jsonObject -> getCoordinate(jsonObject, fieldName))
117+
.min()
118+
.orElse(1);
119+
}
120+
121+
private Optional<JsonObject> findNode(JsonArray jsonNodes, String fullName) {
122+
return StreamSupport.stream(jsonNodes.spliterator(), false)
123+
.map(JsonElement::getAsJsonObject)
124+
.filter(jsonObject -> fullName.equals(jsonObject.get("id").getAsString()))
125+
.findFirst();
77126
}
78127

79-
private void enrichConductingEquipment(GenericVoltageLevel voltageLevel, JsonObject jsonCoductingEquipment) {
80-
var fullName = jsonCoductingEquipment.get("id").getAsString();
81-
var sclConductingEquipment = voltageLevel.getConductingEquipmentByFullName(fullName);
82-
sclConductingEquipment.ifPresent(conductingEquipment ->
83-
conductingEquipment.setXYCoordinates(getCoordinate(jsonCoductingEquipment, "x"),
84-
getCoordinate(jsonCoductingEquipment, "y")));
128+
private long getCoordinateForConductingEquipment(JsonObject jsonObject, GenericBay bay, String fieldName) {
129+
return Math.max(getCoordinate(jsonObject, fieldName) - bay.getCoordinate(fieldName) + 1, 1);
85130
}
86131

87132
private long getCoordinate(JsonObject jsonObject, String fieldName) {

service/src/test/java/org/lfenergy/compas/scl/auto/alignment/model/AbstractGenericEntityTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void getElementsStream_WhenCallingForKnownElement_ThenReturnElements() {
3737
var result = entity.getElementsStream("Bay")
3838
.collect(Collectors.toList());
3939

40-
assertEquals(7, result.size());
40+
assertEquals(8, result.size());
4141
}
4242

4343
@Test

service/src/test/java/org/lfenergy/compas/scl/auto/alignment/model/GenericBayTest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ class GenericBayTest {
2020
public static final String BAY_NAME = "Bay A";
2121
public static final String BUSBAR_NAME = "BusBar A";
2222

23+
private GenericVoltageLevel voltageLevel;
2324
private GenericBay bay;
2425
private GenericBay busbar;
2526

2627
@BeforeEach
2728
void setup() throws IOException {
2829
var scl = new GenericSCL(readSCLElement(BASIC_SCD_FILENAME));
2930
var substation = scl.getSubstation(SUBSTATION_NAME).get();
30-
var voltageLevel = substation.getVoltageLevel(VOLTAGE_LEVEL_NAME).get();
31+
voltageLevel = substation.getVoltageLevel(VOLTAGE_LEVEL_NAME).get();
3132
busbar = voltageLevel.getBays().get(0);
32-
bay = voltageLevel.getBays().get(2);
33+
bay = voltageLevel.getBays().get(3);
3334
}
3435

3536
@Test
@@ -44,6 +45,20 @@ void constructorBay_WhenCreated_ThenElementSet() {
4445
assertEquals(BAY_NAME, bay.getName());
4546
}
4647

48+
@Test
49+
void isBusbar_WhenCalledOnAllBays_ThenExpectedResult() {
50+
var bayNr = 0;
51+
for (var bayOrBusbar : voltageLevel.getBays()) {
52+
// First 2 bays are Busbars, others are Bays.
53+
if (bayNr <= 1) {
54+
assertTrue(bayOrBusbar.isBusbar());
55+
} else {
56+
assertFalse(bayOrBusbar.isBusbar());
57+
}
58+
bayNr++;
59+
}
60+
}
61+
4762
@Test
4863
void isBusbar_WhenCalledOnBusbar_ThenTrueReturned() {
4964
assertTrue(busbar.isBusbar());

service/src/test/java/org/lfenergy/compas/scl/auto/alignment/model/GenericConductingEquipmentTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void setup() throws IOException {
2626
var scl = new GenericSCL(readSCLElement(BASIC_SCD_FILENAME));
2727
var substation = scl.getSubstation(SUBSTATION_NAME).get();
2828
var voltageLevel = substation.getVoltageLevel(VOLTAGE_LEVEL_NAME).get();
29-
var bay = voltageLevel.getBays().get(2);
29+
var bay = voltageLevel.getBays().get(3);
3030
conductingEquipment = bay.getConductingEquipments().get(0);
3131
}
3232

service/src/test/java/org/lfenergy/compas/scl/auto/alignment/model/GenericConnectivityNodeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void setup() throws IOException {
2525
var scl = new GenericSCL(readSCLElement(BASIC_SCD_FILENAME));
2626
var substation = scl.getSubstation(SUBSTATION_NAME).get();
2727
var voltageLevel = substation.getVoltageLevel(VOLTAGE_LEVEL_NAME).get();
28-
var bay = voltageLevel.getBays().get(2);
28+
var bay = voltageLevel.getBays().get(3);
2929
connectivityNode = bay.getConnectivityNodes().get(0);
3030
}
3131

0 commit comments

Comments
 (0)