Skip to content

Commit

Permalink
clean : unused modificationtoexclude (#542)
Browse files Browse the repository at this point in the history
* Clean code : unused endpoint, modificationsToExclude
---------
Signed-off-by: maissa SOUISSI <[email protected]>
  • Loading branch information
souissimai authored Oct 24, 2024
1 parent 909ded4 commit 24c9273
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import lombok.Setter;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;

/**
Expand All @@ -35,9 +33,4 @@ public class BuildInfos {

private List<ReportInfos> reportsInfos = new ArrayList<>();

private Set<UUID> modificationsToExclude = new HashSet<>();

public void addModificationToExclude(UUID modificationUuid) {
modificationsToExclude.add(modificationUuid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ public NetworkModificationResult buildVariant(@NonNull UUID networkUuid, @NonNul
}
modificationInfos.add(
Pair.of(reporterId,
modificationsByGroup.stream()
.filter(e -> !buildInfos.getModificationsToExclude().contains(e.getUuid()))
.collect(Collectors.toList()))
modificationsByGroup)
);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import java.io.IOException;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference;

import static com.powsybl.iidm.network.ReactiveLimitsKind.MIN_MAX;
import static org.gridsuite.modification.server.impacts.TestImpactUtils.*;
Expand Down Expand Up @@ -272,8 +271,7 @@ void runBuildForLineSplits(final MockWebServer server) throws Exception {
BuildInfos buildInfos = new BuildInfos(VariantManagerConstants.INITIAL_VARIANT_ID,
NetworkCreation.VARIANT_ID,
List.of(TEST_GROUP_ID, TEST_GROUP_ID_2),
List.of(new ReportInfos(UUID.randomUUID(), TEST_SUB_REPORTER_ID_1), new ReportInfos(UUID.randomUUID(), TEST_SUB_REPORTER_ID_2)),
new HashSet<>());
List.of(new ReportInfos(UUID.randomUUID(), TEST_SUB_REPORTER_ID_1), new ReportInfos(UUID.randomUUID(), TEST_SUB_REPORTER_ID_2)));
mockMvc.perform(post(uriString, TEST_NETWORK_ID)
.contentType(MediaType.APPLICATION_JSON)
.content(mapper.writeValueAsString(buildInfos)))
Expand All @@ -289,8 +287,7 @@ void runBuildForLineSplits(final MockWebServer server) throws Exception {
BuildInfos newBuildInfos = new BuildInfos(NetworkCreation.VARIANT_ID,
VARIANT_ID_2,
List.of(),
List.of(),
new HashSet<>());
List.of());
mockMvc.perform(post(uriString, TEST_NETWORK_ID)
.contentType(MediaType.APPLICATION_JSON)
.content(mapper.writeValueAsString(newBuildInfos)))
Expand All @@ -314,8 +311,7 @@ void runBuildWithEmptyGroupTest(final MockWebServer server) throws Exception {
BuildInfos buildInfos = new BuildInfos(VariantManagerConstants.INITIAL_VARIANT_ID,
NetworkCreation.VARIANT_ID,
List.of(TEST_GROUP_ID),
List.of(new ReportInfos(UUID.randomUUID(), TEST_SUB_REPORTER_ID_1)),
new HashSet<>());
List.of(new ReportInfos(UUID.randomUUID(), TEST_SUB_REPORTER_ID_1)));
String expectedBody = mapper.writeValueAsString(ReportNode.newRootReportNode()
.withMessageTemplate(TEST_SUB_REPORTER_ID_1.toString(), TEST_SUB_REPORTER_ID_1.toString())
.build());
Expand Down Expand Up @@ -417,8 +413,7 @@ void testIndexationAfterBuild(final MockWebServer server) {
BuildInfos buildInfos = new BuildInfos(VariantManagerConstants.INITIAL_VARIANT_ID,
NetworkCreation.VARIANT_ID,
List.of(TEST_GROUP_ID),
List.of(new ReportInfos(UUID.randomUUID(), TEST_SUB_REPORTER_ID_1)),
new HashSet<>());
List.of(new ReportInfos(UUID.randomUUID(), TEST_SUB_REPORTER_ID_1)));

// Build variant
networkModificationService.buildVariant(TEST_NETWORK_ID, buildInfos);
Expand Down Expand Up @@ -696,8 +691,7 @@ void runBuildTest(final MockWebServer server) throws Exception {
BuildInfos buildInfos = new BuildInfos(VariantManagerConstants.INITIAL_VARIANT_ID,
NetworkCreation.VARIANT_ID,
List.of(TEST_GROUP_ID, TEST_GROUP_ID_2),
List.of(new ReportInfos(UUID.randomUUID(), TEST_SUB_REPORTER_ID_1), new ReportInfos(UUID.randomUUID(), TEST_SUB_REPORTER_ID_2)),
new HashSet<>());
List.of(new ReportInfos(UUID.randomUUID(), TEST_SUB_REPORTER_ID_1), new ReportInfos(UUID.randomUUID(), TEST_SUB_REPORTER_ID_2)));
String buildInfosJson = objectWriter.writeValueAsString(buildInfos);
mockMvc.perform(post(uriString, TEST_NETWORK_ID).contentType(MediaType.APPLICATION_JSON).content(buildInfosJson))
.andExpect(status().isOk());
Expand Down Expand Up @@ -795,8 +789,7 @@ void runBuildTest(final MockWebServer server) throws Exception {
BuildInfos newBuildInfos = new BuildInfos(NetworkCreation.VARIANT_ID,
VARIANT_ID_2,
Collections.emptyList(),
Collections.emptyList(),
new HashSet<>());
Collections.emptyList());
buildInfosJson = objectWriter.writeValueAsString(newBuildInfos);
mockMvc.perform(post(uriString, TEST_NETWORK_ID).contentType(MediaType.APPLICATION_JSON).content(buildInfosJson)).andExpect(status().isOk());

Expand All @@ -820,80 +813,6 @@ void runBuildTest(final MockWebServer server) throws Exception {
assertEquals(1, tbseqVariant1.size());
assertEquals(tbseqVariant1.size(), tbseqVariant2.size());

// deactivate some modifications and rebuild VARIANT_ID
network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, NetworkCreation.VARIANT_ID, true);

AtomicReference<UUID> lineModificationEntityUuid = new AtomicReference<>();
AtomicReference<UUID> loadCreationEntityUuid = new AtomicReference<>();
AtomicReference<UUID> equipmentDeletionEntityUuid = new AtomicReference<>();
List<ModificationInfos> modificationsInfos = networkModificationService.getNetworkModifications(TEST_GROUP_ID, false, true);
modificationsInfos.addAll(networkModificationService.getNetworkModifications(TEST_GROUP_ID_2, false, true));
modificationsInfos.forEach(modificationInfos -> {
if (modificationInfos.getClass().equals(EquipmentAttributeModificationInfos.class)) {
if (((EquipmentAttributeModificationInfos) modificationInfos).getEquipmentId().equals("line1")) {
lineModificationEntityUuid.set(modificationInfos.getUuid());
}
} else if (modificationInfos.getClass().equals(LoadCreationInfos.class)) {
if (((LoadCreationInfos) modificationInfos).getEquipmentId().equals("newLoad1")) {
loadCreationEntityUuid.set(modificationInfos.getUuid());
}
} else if (modificationInfos.getClass().equals(EquipmentDeletionInfos.class)) {
if (((EquipmentDeletionInfos) modificationInfos).getEquipmentId().equals("v2shunt")) {
equipmentDeletionEntityUuid.set(modificationInfos.getUuid());
}
}
});

buildInfos.addModificationToExclude(lineModificationEntityUuid.get());
buildInfos.addModificationToExclude(loadCreationEntityUuid.get());
buildInfos.addModificationToExclude(equipmentDeletionEntityUuid.get());
buildInfosJson = objectWriter.writeValueAsString(buildInfos);

mockMvc.perform(post(uriString, TEST_NETWORK_ID).content(buildInfosJson).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());

resultMessage = output.receive(TIMEOUT, buildResultDestination);
assertNotNull(resultMessage);
assertEquals("me", resultMessage.getHeaders().get("receiver"));
// 1 : SWITCH equipments are reduced to collection impact
// + 2 substation modifications
// = 3
testElementImpacts(mapper, new String(resultMessage.getPayload()), 3, Set.of(IdentifiableType.SWITCH), Set.of("newSubstation", "s1"));
buildMessage = output.receive(TIMEOUT, consumeBuildDestination);
assertNotNull(buildMessage);
assertEquals("me", buildMessage.getHeaders().get("receiver"));

// test that only active modifications have been made on variant VARIANT_ID
network.getVariantManager().setWorkingVariant(NetworkCreation.VARIANT_ID);
assertTrue(network.getSwitch("v1d1").isOpen());
assertNull(network.getLine("line1").getExtension(OperatingStatus.class));
assertEquals(55., network.getGenerator("idGenerator").getTargetP(), 0.1);
assertEquals(2, network.getTwoWindingsTransformer("trf1").getRatioTapChanger().getTapPosition());
assertEquals(0, network.getThreeWindingsTransformer("trf6").getLeg1().getPhaseTapChanger().getTapPosition());
assertNotNull(network.getLoad("newLoad"));
assertNull(network.getLoad("newLoad1"));
assertEquals(EnergySource.HYDRO, network.getGenerator(NEW_GENERATOR_ID).getEnergySource());
assertEquals("v2", network.getGenerator(NEW_GENERATOR_ID).getTerminal().getVoltageLevel().getId());
assertEquals(500., network.getGenerator(NEW_GENERATOR_ID).getMaxP(), 0.1);
assertEquals(100., network.getGenerator(NEW_GENERATOR_ID).getTargetP(), 0.1);
assertTrue(network.getGenerator(NEW_GENERATOR_ID).isVoltageRegulatorOn());
assertEquals(225., network.getGenerator(NEW_GENERATOR_ID).getTargetV(), 0.1);
assertEquals("v1", network.getLine("newLine").getTerminal1().getVoltageLevel().getId());
assertEquals("v2", network.getLine("newLine").getTerminal2().getVoltageLevel().getId());
assertEquals(4., network.getLine("newLine").getB1(), 0.1);
assertEquals("v1", network.getTwoWindingsTransformer("new2wt").getTerminal1().getVoltageLevel().getId());
assertEquals("v2", network.getTwoWindingsTransformer("new2wt").getTerminal2().getVoltageLevel().getId());
assertEquals(2., network.getTwoWindingsTransformer("new2wt").getX(), 0.1);
assertEquals(5., network.getTwoWindingsTransformer("new2wt").getRatedU1(), 0.1);
assertEquals(1, network.getTwoWindingsTransformer("new2wt").getRatedS(), 0.1);
assertEquals(4, network.getTwoWindingsTransformer("new2wt").getRatioTapChanger().getStepCount());
assertEquals(3, network.getTwoWindingsTransformer("new2wt").getPhaseTapChanger().getStepCount());
assertEquals(PhaseTapChanger.RegulationMode.CURRENT_LIMITER, network.getTwoWindingsTransformer("new2wt").getPhaseTapChanger().getRegulationMode());
assertNotNull(network.getShuntCompensator("v2shunt"));
assertEquals(Country.FR, network.getSubstation("newSubstation").getCountry().orElse(Country.AF));
assertNotNull(network.getVoltageLevel("vl9"));
assertNotNull(network.getShuntCompensator("shunt9"));

TestUtils.purgeRequests(server);
}

Expand All @@ -911,8 +830,7 @@ void runBuildWithStashedModificationsTest(final MockWebServer server) {
BuildInfos buildInfos = new BuildInfos(VariantManagerConstants.INITIAL_VARIANT_ID,
NetworkCreation.VARIANT_ID,
List.of(TEST_GROUP_ID),
List.of(new ReportInfos(UUID.randomUUID(), TEST_SUB_REPORTER_ID_1)),
new HashSet<>());
List.of(new ReportInfos(UUID.randomUUID(), TEST_SUB_REPORTER_ID_1)));
networkModificationService.buildVariant(TEST_NETWORK_ID, buildInfos);

// test that only non stashed modifications have been made on variant VARIANT_ID
Expand All @@ -937,8 +855,7 @@ void stopBuildTest() throws Exception {
BuildInfos buildInfos = new BuildInfos(VariantManagerConstants.INITIAL_VARIANT_ID,
NetworkCreation.VARIANT_ID,
List.of(TEST_GROUP_ID),
List.of(new ReportInfos(UUID.randomUUID(), TEST_SUB_REPORTER_ID_1)),
Set.of());
List.of(new ReportInfos(UUID.randomUUID(), TEST_SUB_REPORTER_ID_1)));
String buildInfosJson = mapper.writeValueAsString(buildInfos);
CompletableFuture.runAsync(() -> {
try {
Expand Down Expand Up @@ -976,8 +893,7 @@ void runBuildWithReportErrorTest(final MockWebServer server) throws Exception {
BuildInfos buildInfos = new BuildInfos(VariantManagerConstants.INITIAL_VARIANT_ID,
NetworkCreation.VARIANT_ID,
List.of(TEST_GROUP_ID),
List.of(new ReportInfos(TEST_ERROR_REPORT_ID, TEST_SUB_REPORTER_ID_1)),
Set.of());
List.of(new ReportInfos(TEST_ERROR_REPORT_ID, TEST_SUB_REPORTER_ID_1)));
mockMvc.perform(post(uriString, TEST_NETWORK_ID)
.contentType(MediaType.APPLICATION_JSON)
.content(mapper.writeValueAsString(buildInfos)))
Expand Down

0 comments on commit 24c9273

Please sign in to comment.