Skip to content

Commit 053789d

Browse files
Update section count in shunt compensator creation (#286)
* update section count in shunt compensator creation Signed-off-by: walid-sahnoun <[email protected]>
1 parent 057e450 commit 053789d

File tree

4 files changed

+56
-37
lines changed

4 files changed

+56
-37
lines changed

src/main/java/org/gridsuite/modification/server/entities/equipment/creation/ShuntCompensatorCreationEntity.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.powsybl.iidm.network.extensions.ConnectablePosition;
1111
import lombok.Getter;
1212
import lombok.NoArgsConstructor;
13+
import org.apache.commons.lang3.BooleanUtils;
1314
import org.gridsuite.modification.server.dto.ModificationInfos;
1415
import org.gridsuite.modification.server.dto.ShuntCompensatorCreationInfos;
1516
import org.gridsuite.modification.server.dto.ShuntCompensatorType;
@@ -56,12 +57,12 @@ public class ShuntCompensatorCreationEntity extends InjectionCreationEntity {
5657

5758
public ShuntCompensatorCreationEntity(ShuntCompensatorCreationInfos creationInfos) {
5859
super(creationInfos);
59-
maximumNumberOfSections = creationInfos.getMaximumNumberOfSections();
60-
currentNumberOfSections = creationInfos.getCurrentNumberOfSections();
60+
maximumNumberOfSections = creationInfos.getMaximumNumberOfSections() != null ? creationInfos.getMaximumNumberOfSections() : 1;
61+
currentNumberOfSections = creationInfos.getCurrentNumberOfSections() != null ? creationInfos.getCurrentNumberOfSections() : 1;
6162
susceptancePerSection = creationInfos.getSusceptancePerSection();
6263
qAtNominalV = creationInfos.getQAtNominalV();
6364
shuntCompensatorType = creationInfos.getShuntCompensatorType();
64-
isIdenticalSections = creationInfos.getIsIdenticalSection();
65+
isIdenticalSections = BooleanUtils.toBooleanDefaultIfNull(creationInfos.getIsIdenticalSection(), true);
6566
connectionName = creationInfos.getConnectionName();
6667
connectionDirection = creationInfos.getConnectionDirection();
6768
connectionPosition = creationInfos.getConnectionPosition();
@@ -71,12 +72,12 @@ public ShuntCompensatorCreationEntity(ShuntCompensatorCreationInfos creationInfo
7172
public void update(ModificationInfos modificationInfos) {
7273
super.update(modificationInfos);
7374
ShuntCompensatorCreationInfos shuntCompensatorCreationInfos = (ShuntCompensatorCreationInfos) modificationInfos;
74-
maximumNumberOfSections = shuntCompensatorCreationInfos.getMaximumNumberOfSections();
75-
currentNumberOfSections = shuntCompensatorCreationInfos.getCurrentNumberOfSections();
75+
maximumNumberOfSections = shuntCompensatorCreationInfos.getMaximumNumberOfSections() != null ? shuntCompensatorCreationInfos.getMaximumNumberOfSections() : 1;
76+
currentNumberOfSections = shuntCompensatorCreationInfos.getCurrentNumberOfSections() != null ? shuntCompensatorCreationInfos.getCurrentNumberOfSections() : 1;
7677
susceptancePerSection = shuntCompensatorCreationInfos.getSusceptancePerSection();
7778
qAtNominalV = shuntCompensatorCreationInfos.getQAtNominalV();
7879
shuntCompensatorType = shuntCompensatorCreationInfos.getShuntCompensatorType();
79-
isIdenticalSections = shuntCompensatorCreationInfos.getIsIdenticalSection();
80+
isIdenticalSections = BooleanUtils.toBooleanDefaultIfNull(shuntCompensatorCreationInfos.getIsIdenticalSection(), true);
8081
connectionName = shuntCompensatorCreationInfos.getConnectionName();
8182
connectionDirection = shuntCompensatorCreationInfos.getConnectionDirection();
8283
connectionPosition = shuntCompensatorCreationInfos.getConnectionPosition();

src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreation.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public void apply(Network network, Reporter subReporter) {
4949
? susceptancePerSection
5050
: -susceptancePerSection);
5151
}
52+
determinateSectionCount(modificationInfos);
5253
if (voltageLevel.getTopologyKind() == TopologyKind.NODE_BREAKER) {
5354
ShuntCompensatorAdder shuntCompensatorAdder = createShuntAdderInNodeBreaker(voltageLevel, modificationInfos);
5455
var position = ModificationUtils.getInstance().getPosition(modificationInfos.getConnectionPosition(),
@@ -72,6 +73,23 @@ public void apply(Network network, Reporter subReporter) {
7273
}
7374
}
7475

76+
private void determinateSectionCount(ShuntCompensatorCreationInfos modificationInfos) {
77+
if (modificationInfos.getSusceptancePerSection() != null) {
78+
if (modificationInfos.getSusceptancePerSection() == 0) {
79+
modificationInfos.setCurrentNumberOfSections(0);
80+
} else {
81+
modificationInfos.setCurrentNumberOfSections(1);
82+
}
83+
}
84+
if (modificationInfos.getQAtNominalV() != null) {
85+
if (modificationInfos.getQAtNominalV() == 0) {
86+
modificationInfos.setCurrentNumberOfSections(0);
87+
} else {
88+
modificationInfos.setCurrentNumberOfSections(1);
89+
}
90+
}
91+
}
92+
7593
private ShuntCompensatorAdder createShuntAdderInNodeBreaker(VoltageLevel voltageLevel, ShuntCompensatorCreationInfos shuntCompensatorInfos) {
7694
// creating the shunt compensator
7795
ShuntCompensatorAdder shuntAdder = voltageLevel.newShuntCompensator()
@@ -98,7 +116,7 @@ private void createShuntInBusBreaker(VoltageLevel voltageLevel, ShuntCompensator
98116
.setConnectableBus(bus.getId())
99117
.newLinearModel()
100118
.setBPerSection(shuntCompensatorInfos.getSusceptancePerSection())
101-
.setMaximumSectionCount(shuntCompensatorInfos.getMaximumNumberOfSections())
119+
.setMaximumSectionCount(shuntCompensatorInfos.getMaximumNumberOfSections() != null ? shuntCompensatorInfos.getMaximumNumberOfSections() : 1)
102120
.add()
103121
.add();
104122
}

src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreationInBusBreakerTest.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,8 @@ public class ShuntCompensatorCreationInBusBreakerTest extends AbstractNetworkMod
3434
@Test
3535
public void testCreateWithErrors() throws Exception {
3636
ShuntCompensatorCreationInfos shunt = (ShuntCompensatorCreationInfos) buildModification();
37-
shunt.setCurrentNumberOfSections(6);
38-
shunt.setMaximumNumberOfSections(2);
39-
String shuntJson = mapper.writeValueAsString(shunt);
40-
mockMvc.perform(post(getNetworkModificationUri()).content(shuntJson).contentType(MediaType.APPLICATION_JSON))
41-
.andExpect(status().isOk());
42-
assertLogMessage(String.format("Shunt compensator '%s': the current number (%s) of section should be lesser than the maximum number of section (%s)", shunt.getEquipmentId(), 6, 2),
43-
shunt.getErrorType().name(), reportService);
44-
4537
shunt.setBusOrBusbarSectionId("notFoundBus");
46-
shuntJson = mapper.writeValueAsString(shunt);
38+
String shuntJson = mapper.writeValueAsString(shunt);
4739
mockMvc.perform(post(getNetworkModificationUri()).content(shuntJson).contentType(MediaType.APPLICATION_JSON))
4840
.andExpect(status().isOk());
4941
assertLogMessage(new NetworkModificationException(BUS_NOT_FOUND, "notFoundBus").getMessage(),
@@ -61,9 +53,9 @@ protected ModificationInfos buildModification() {
6153
.date(ZonedDateTime.now().truncatedTo(ChronoUnit.MICROS))
6254
.equipmentId("shuntOneId")
6355
.equipmentName("hopOne")
64-
.currentNumberOfSections(4)
65-
.maximumNumberOfSections(9)
66-
.susceptancePerSection(1.)
56+
.currentNumberOfSections(0)
57+
.maximumNumberOfSections(1)
58+
.susceptancePerSection(0.)
6759
.isIdenticalSection(true)
6860
.voltageLevelId("v2")
6961
.busOrBusbarSectionId("bus2")
@@ -78,10 +70,10 @@ protected ModificationInfos buildModificationUpdate() {
7870
.date(ZonedDateTime.now().truncatedTo(ChronoUnit.MICROS))
7971
.equipmentId("shuntOneIdEdited")
8072
.equipmentName("hopEdited")
81-
.currentNumberOfSections(6)
82-
.maximumNumberOfSections(12)
73+
.currentNumberOfSections(1)
74+
.maximumNumberOfSections(1)
8375
.susceptancePerSection(1.)
84-
.isIdenticalSection(false)
76+
.isIdenticalSection(true)
8577
.voltageLevelId("v4")
8678
.busOrBusbarSectionId("bus3")
8779
.connectionName("cnEdited")

src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorCreationInNodeBreakerTest.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage;
2929
import static org.junit.Assert.assertNotNull;
3030
import static org.junit.Assert.assertNull;
31+
import static org.junit.jupiter.api.Assertions.assertEquals;
3132
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
3233
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
3334

@@ -45,9 +46,9 @@ protected ModificationInfos buildModification() {
4546
.date(ZonedDateTime.now().truncatedTo(ChronoUnit.MICROS))
4647
.equipmentId("shuntOneId")
4748
.equipmentName("hop")
48-
.currentNumberOfSections(4)
49-
.maximumNumberOfSections(9)
50-
.susceptancePerSection(1.)
49+
.currentNumberOfSections(0)
50+
.maximumNumberOfSections(1)
51+
.susceptancePerSection(0.)
5152
.isIdenticalSection(true)
5253
.voltageLevelId("v2")
5354
.busOrBusbarSectionId("1B")
@@ -64,8 +65,8 @@ protected ModificationInfos buildModificationUpdate() {
6465
.equipmentId("shuntOneIdEdited")
6566
.equipmentName("hopEdited")
6667
.currentNumberOfSections(6)
67-
.maximumNumberOfSections(12)
68-
.susceptancePerSection(1.)
68+
.maximumNumberOfSections(1)
69+
.susceptancePerSection(0.)
6970
.isIdenticalSection(false)
7071
.voltageLevelId("v4")
7172
.busOrBusbarSectionId("1.A")
@@ -87,19 +88,10 @@ protected void assertNetworkAfterDeletion() {
8788
@Test
8889
public void testCreateWithError() throws Exception {
8990
ShuntCompensatorCreationInfos modificationToCreate = (ShuntCompensatorCreationInfos) buildModification();
90-
// Current number of sections above maximum allowed
91-
modificationToCreate.setIsIdenticalSection(false);
92-
modificationToCreate.setCurrentNumberOfSections(6);
93-
modificationToCreate.setMaximumNumberOfSections(2);
94-
String modificationToCreateJson = mapper.writeValueAsString(modificationToCreate);
95-
mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
96-
.andExpect(status().isOk());
97-
assertNull(getNetwork().getShuntCompensator(modificationToCreate.getEquipmentId()));
98-
9991
// try to create an existing equipment
10092
modificationToCreate.setEquipmentId("v5shunt");
10193
assertNotNull(getNetwork().getShuntCompensator("v5shunt"));
102-
modificationToCreateJson = mapper.writeValueAsString(modificationToCreate);
94+
String modificationToCreateJson = mapper.writeValueAsString(modificationToCreate);
10395
mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
10496
.andExpect(status().isOk());
10597
assertLogMessage(new NetworkModificationException(SHUNT_COMPENSATOR_ALREADY_EXISTS, "v5shunt").getMessage(),
@@ -139,4 +131,20 @@ public void testCreateWithQAtNominalV() throws Exception {
139131
createdModification = (ShuntCompensatorCreationInfos) modificationRepository.getModifications(getGroupId(), false, true).get(1);
140132
assertThat(createdModification).recursivelyEquals(dto);
141133
}
134+
135+
@Test
136+
public void testCreateToAssignSectionCount() throws Exception {
137+
ShuntCompensatorCreationInfos dto = (ShuntCompensatorCreationInfos) buildModification();
138+
dto.setQAtNominalV(0.);
139+
String modificationToCreateJson = mapper.writeValueAsString(dto);
140+
mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
141+
.andExpect(status().isOk()).andReturn();
142+
ShuntCompensatorCreationInfos createdModification = (ShuntCompensatorCreationInfos) modificationRepository.getModifications(getGroupId(), false, true).get(0);
143+
assertEquals(0, createdModification.getCurrentNumberOfSections());
144+
modificationToCreateJson = mapper.writeValueAsString(dto);
145+
mockMvc.perform(post(getNetworkModificationUri()).content(modificationToCreateJson).contentType(MediaType.APPLICATION_JSON))
146+
.andExpect(status().isOk()).andReturn();
147+
createdModification = (ShuntCompensatorCreationInfos) modificationRepository.getModifications(getGroupId(), false, true).get(0);
148+
assertEquals(0, createdModification.getCurrentNumberOfSections());
149+
}
142150
}

0 commit comments

Comments
 (0)