Skip to content

Commit f217fbe

Browse files
author
Rob Tjalma
authored
Merge pull request #45 from com-pas/calculate-power-transformers
Calculate PowerTransformer X/Y Coordinates using JSON
2 parents a3abe9a + 35c3ed9 commit f217fbe

File tree

5 files changed

+37
-106
lines changed

5 files changed

+37
-106
lines changed

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: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@
77
import com.google.gson.JsonElement;
88
import com.google.gson.JsonObject;
99
import com.google.gson.JsonParser;
10-
import org.lfenergy.compas.scl.auto.alignment.model.GenericBay;
11-
import org.lfenergy.compas.scl.auto.alignment.model.GenericConductingEquipment;
12-
import org.lfenergy.compas.scl.auto.alignment.model.GenericSCL;
13-
import org.lfenergy.compas.scl.auto.alignment.model.GenericSubstation;
10+
import org.lfenergy.compas.scl.auto.alignment.model.*;
1411

1512
import java.util.Optional;
16-
import java.util.concurrent.atomic.AtomicLong;
1713
import java.util.stream.StreamSupport;
1814

1915
import static org.lfenergy.compas.scl.auto.alignment.common.CommonUtil.cleanSXYDeclarationAndAttributes;
@@ -37,41 +33,61 @@ public void enrich() {
3733

3834
// Next process the VoltageLevels.
3935
if (jsonSubstation.has("voltageLevels")) {
40-
jsonSubstation.getAsJsonArray("voltageLevels")
41-
.forEach(jsonVoltageLevel -> enrichVoltageLevel(substation, jsonVoltageLevel.getAsJsonObject()));
36+
JsonArray jsonNodes = jsonSubstation.getAsJsonArray("voltageLevels");
37+
substation.getVoltageLevels()
38+
.forEach(voltageLevel -> enrichVoltageLevel(jsonNodes, voltageLevel));
4239
}
4340

44-
AtomicLong pwtCoordinate = new AtomicLong(1);
45-
substation.getPowerTransformers().forEach(powerTransformer ->
46-
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+
}
4746
});
4847
}
4948

50-
private void enrichVoltageLevel(GenericSubstation substation, JsonObject jsonVoltageLevel) {
51-
var voltageLevelFullName = jsonVoltageLevel.get("voltageLevelInfos").getAsJsonObject().get("id").getAsString();
52-
var sclVoltageLevel = substation.getVoltageLevelByFullName(voltageLevelFullName);
53-
sclVoltageLevel.ifPresent(voltageLevel -> {
54-
voltageLevel.setXYCoordinates(getCoordinate(jsonVoltageLevel, "x"),
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+
}
56+
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"),
5562
getCoordinate(jsonVoltageLevel, "y"));
5663

5764
if (jsonVoltageLevel.has("nodes")) {
58-
JsonArray jsonNodes = jsonVoltageLevel.getAsJsonArray("nodes");
65+
JsonArray jsonSubNodes = jsonVoltageLevel.getAsJsonArray("nodes");
5966
voltageLevel.getBays()
6067
.forEach(bay -> {
6168
if (bay.isBusbar()) {
62-
enrichBusbar(jsonNodes, bay);
69+
enrichBusbar(jsonSubNodes, bay);
6370
} else {
64-
enrichBay(jsonNodes, bay);
71+
enrichBay(jsonSubNodes, bay);
6572
}
6673
});
6774
}
6875
});
6976
}
7077

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+
7185
private void enrichBusbar(JsonArray jsonNodes, GenericBay busbar) {
7286
var jsonObject = findNode(jsonNodes, busbar.getFullName());
7387
jsonObject.ifPresent(jsonBusbar ->
74-
busbar.setXYCoordinates(getCoordinate(jsonBusbar, "x"), getCoordinate(jsonBusbar, "y")));
88+
busbar.setXYCoordinates(
89+
getCoordinate(jsonBusbar, "x"),
90+
getCoordinate(jsonBusbar, "y")));
7591
}
7692

7793
private void enrichBay(JsonArray jsonNodes, GenericBay bay) {
@@ -102,10 +118,10 @@ private long getMinimumCoordinate(JsonArray jsonNodes, GenericBay bay, String fi
102118
.orElse(1);
103119
}
104120

105-
private Optional<JsonObject> findNode(JsonArray jsonNodes, String fullname) {
121+
private Optional<JsonObject> findNode(JsonArray jsonNodes, String fullName) {
106122
return StreamSupport.stream(jsonNodes.spliterator(), false)
107123
.map(JsonElement::getAsJsonObject)
108-
.filter(jsonObject -> fullname.equals(jsonObject.get("id").getAsString()))
124+
.filter(jsonObject -> fullName.equals(jsonObject.get("id").getAsString()))
109125
.findFirst();
110126
}
111127

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,4 @@ void getVoltageLevel_WhenCalledWithBlankName_ThenEmptyOptional() {
9595

9696
assertFalse(result.isPresent());
9797
}
98-
99-
@Test
100-
void getVoltageLevelByFullName_WhenCalled_ThenSpecificVoltageLevelReturned() {
101-
var result = substation.getVoltageLevelByFullName("AA1/J1");
102-
103-
assertTrue(result.isPresent());
104-
assertEquals(VOLTAGE_LEVEL_NAME, result.get().getName());
105-
}
106-
107-
@Test
108-
void getVoltageLevelByFullName_WhenCalledWithBlankName_ThenEmptyOptional() {
109-
var result = substation.getVoltageLevelByFullName("");
110-
111-
assertFalse(result.isPresent());
112-
}
11398
}

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

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import static org.lfenergy.compas.scl.auto.alignment.exception.SclAutoAlignmentErrorCode.NO_VOLTAGE_FOUND_ERROR_CODE;
1616
import static org.lfenergy.compas.scl.auto.alignment.model.GenericBayTest.BAY_NAME;
1717
import static org.lfenergy.compas.scl.auto.alignment.model.GenericBayTest.BUSBAR_NAME;
18-
import static org.lfenergy.compas.scl.auto.alignment.model.GenericConductingEquipmentTest.CE_NAME;
1918
import static org.lfenergy.compas.scl.auto.alignment.model.GenericSCLTest.BASIC_SCD_FILENAME;
2019
import static org.lfenergy.compas.scl.auto.alignment.model.GenericSubstationTest.SUBSTATION_NAME;
2120

@@ -63,41 +62,4 @@ void getBays_WhenCalled_ThenVoltageLevelsReturned() {
6362
assertEquals(BUSBAR_NAME, result.get(0).getName());
6463
assertEquals(BAY_NAME, result.get(2).getName());
6564
}
66-
67-
@Test
68-
void getBusbarByFullName_WhenCalled_ThenReturnTheBusbar() {
69-
var result = voltageLevel.getBusbarByFullName("AA1/J1/BusBar A");
70-
71-
assertTrue(result.isPresent());
72-
assertEquals(BUSBAR_NAME, result.get().getName());
73-
}
74-
75-
@Test
76-
void getBusbarByFullName_WhenCalledForBay_ThenEmptyOptional() {
77-
var result = voltageLevel.getBusbarByFullName("AA1/J1/Bay A");
78-
79-
assertFalse(result.isPresent());
80-
}
81-
82-
@Test
83-
void getBusbarByFullName_WhenCalledWithEmptyString_ThenEmptyOptional() {
84-
var result = voltageLevel.getBusbarByFullName("");
85-
86-
assertFalse(result.isPresent());
87-
}
88-
89-
@Test
90-
void getConductingEquipmentByFullName_WhenCalled_ThenConductingEquipmentReturned() {
91-
var result = voltageLevel.getConductingEquipmentByFullName("AA1/J1/Bay A/QB1");
92-
93-
assertTrue(result.isPresent());
94-
assertEquals(CE_NAME, result.get().getName());
95-
}
96-
97-
@Test
98-
void getConductingEquipmentByFullName_WhenCalledWithEmptyString_ThenEmptyOptional() {
99-
var result = voltageLevel.getConductingEquipmentByFullName("");
100-
101-
assertFalse(result.isPresent());
102-
}
10365
}

0 commit comments

Comments
 (0)