From 64cc1d2ca87b10b28eb2f7e4ba3ca6e4dcc7bc60 Mon Sep 17 00:00:00 2001 From: AbdelHedhili Date: Mon, 2 Mar 2020 13:34:21 +0100 Subject: [PATCH 1/8] implement remove for danglingLines Signed-off-by: AbdelHedhili --- .../BufferedRestNetworkStoreClient.java | 9 ++++++++ .../store/client/CacheNetworkStoreClient.java | 9 ++++++++ .../store/client/DanglingLineImpl.java | 5 ++++ .../store/client/NetworkObjectIndex.java | 4 ++++ .../store/client/NetworkStoreClient.java | 2 ++ .../PreloadingRestNetworkStoreClient.java | 8 ++++++- .../store/client/RestNetworkStoreClient.java | 7 ++++++ .../store/integration/NetworkStoreIT.java | 23 ++++++++++--------- .../store/server/NetworkStoreController.java | 12 ++++++++++ .../store/server/NetworkStoreRepository.java | 4 ++++ 10 files changed, 71 insertions(+), 12 deletions(-) diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/BufferedRestNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/BufferedRestNetworkStoreClient.java index fd01b221f..f82ec3ac0 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/BufferedRestNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/BufferedRestNetworkStoreClient.java @@ -10,6 +10,7 @@ import java.util.*; import java.util.function.BiConsumer; +import java.util.stream.Collectors; /** * @author Geoffroy Jamgotchian @@ -462,6 +463,14 @@ public int getDanglingLineCount(UUID networkUuid) { return client.getDanglingLineCount(networkUuid); } + @Override + public void removeDanglingLine(UUID networkUuid, String danglingLineId) { + List> dlToRemove = + danglingLineResourcesToFlush.get(networkUuid).stream().filter(danglingLineAttributesResource -> danglingLineAttributesResource.getId().equals(danglingLineId)).collect(Collectors.toList()); + dlToRemove.forEach(danglingLineAttributesResource -> danglingLineResourcesToFlush.get(networkUuid).remove(danglingLineAttributesResource)); + client.removeDanglingLine(networkUuid, danglingLineId); + } + @Override public void createConfiguredBuses(UUID networkUuid, List> busesRessources) { busResourcesToFlush.computeIfAbsent(networkUuid, k -> new ArrayList<>()).addAll(busesRessources); diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/CacheNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/CacheNetworkStoreClient.java index b2b32009e..e3b1cf3fe 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/CacheNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/CacheNetworkStoreClient.java @@ -87,6 +87,10 @@ int getResourceCount() { List> getContainerResources(String containerId) { return resourcesByContainerId.computeIfAbsent(containerId, k -> new ArrayList<>()); } + + void removeResource(String resourceId) { + resourcesById.remove(resourceId); + } } private final NestedResources voltageLevelResources = new NestedResources<>(resource -> resource.getAttributes().getSubstationId()); @@ -625,6 +629,11 @@ public int getDanglingLineCount(UUID networkUuid) { return getNetworkCache(networkUuid).getDanglingLineResources().getResourceCount(); } + @Override + public void removeDanglingLine(UUID networkUuid, String danglingLineId) { + getNetworkCache(networkUuid).getDanglingLineResources().removeResource(danglingLineId); + } + @Override public void createConfiguredBuses(UUID networkUuid, List> busesResources) { getNetworkCache(networkUuid).getBusResources().addResources(busesResources); diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/DanglingLineImpl.java b/network-store-client/src/main/java/com/powsybl/network/store/client/DanglingLineImpl.java index 63f507c84..841bf30fb 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/DanglingLineImpl.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/DanglingLineImpl.java @@ -32,6 +32,11 @@ public ConnectableType getType() { return ConnectableType.DANGLING_LINE; } + @Override + public void remove() { + index.removeDanglingLine(resource.getId()); + } + @Override protected DanglingLine getInjection() { return this; diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkObjectIndex.java b/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkObjectIndex.java index 48792c973..4b5039a4e 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkObjectIndex.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkObjectIndex.java @@ -601,6 +601,10 @@ public Identifiable getIdentifiable(String id) { return null; } + public void removeDanglingLine(String danglingLineId) { + storeClient.removeDanglingLine(network.getUuid(), danglingLineId); + } + //buses Optional getBus(String id) { diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkStoreClient.java index 951f80a24..33087a5ca 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkStoreClient.java @@ -204,6 +204,8 @@ public interface NetworkStoreClient { int getDanglingLineCount(UUID networkUuid); + void removeDanglingLine(UUID networkUuid, String danglingLineId); + // Bus void createConfiguredBuses(UUID networkUuid, List> busesRessources); diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingRestNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingRestNetworkStoreClient.java index 9b4e3d316..0ccb68daa 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingRestNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingRestNetworkStoreClient.java @@ -101,7 +101,6 @@ public Optional> getNetwork(UUID networkUuid) { public void deleteNetwork(UUID networkUuid) { restClient.deleteNetwork(networkUuid); cacheClient.deleteNetwork(networkUuid); - cachedResourceTypes.remove(networkUuid); } @Override @@ -511,6 +510,13 @@ public int getDanglingLineCount(UUID networkUuid) { return restClient.getDanglingLineCount(networkUuid); } + @Override + public void removeDanglingLine(UUID networkUuid, String danglingLineId) { + restClient.removeDanglingLine(networkUuid, danglingLineId); + cacheClient.removeDanglingLine(networkUuid, danglingLineId); + cachedResourceTypes.remove(networkUuid, danglingLineId); + } + @Override public void createConfiguredBuses(UUID networkUuid, List> busesResources) { restClient.createConfiguredBuses(networkUuid, busesResources); diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java index deb9f035b..fba0d1593 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java @@ -504,6 +504,13 @@ public int getDanglingLineCount(UUID networkUuid) { return getTotalCount("dangling line", "/networks/{networkUuid}/dangling-lines?limit=0", networkUuid); } + @Override + public void removeDanglingLine(UUID networkUuid, String danglingLineId) { + resources.delete("/networks/{networkUuid}/dangling-lines/{danglingLineId}", networkUuid, danglingLineId); + } + + //ConfiguredBus + @Override public void createConfiguredBuses(UUID networkUuid, List> busesResources) { create("bus", "/networks/{networkUuid}/configured-buses", busesResources, networkUuid); diff --git a/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java b/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java index e8e3640b2..67d1efb8b 100644 --- a/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java +++ b/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java @@ -12,6 +12,7 @@ import com.powsybl.commons.datasource.ResourceDataSource; import com.powsybl.commons.datasource.ResourceSet; import com.powsybl.entsoe.util.MergedXnode; +import com.powsybl.entsoe.util.Xnode; import com.powsybl.iidm.network.*; import com.powsybl.iidm.network.VoltageLevel.NodeBreakerView.InternalConnection; import com.powsybl.iidm.network.test.FictitiousSwitchFactory; @@ -21,6 +22,7 @@ import com.powsybl.network.store.server.CassandraConfig; import com.powsybl.network.store.server.CassandraConstants; import com.powsybl.network.store.server.NetworkStoreApplication; +import com.powsybl.sld.iidm.extensions.ConnectablePosition; import com.powsybl.ucte.converter.UcteImporter; import org.apache.commons.io.FilenameUtils; import org.cassandraunit.spring.CassandraDataSet; @@ -664,17 +666,16 @@ public void testUcteNetwork() { Map networkIds = service.getNetworkIds(); assertEquals(1, networkIds.size()); Network readNetwork = service.getNetwork(networkIds.keySet().stream().findFirst().get()); - //TODO uncomment when remove method for DL are implemented -// assertEquals(1, readNetwork.getDanglingLineCount()); -// assertEquals("XG__F_21", readNetwork.getDanglingLineStream().findFirst().get().getUcteXnodeCode()); -// Xnode xnode = (Xnode) readNetwork.getDanglingLineStream().findFirst().get().getExtensionByName("xnode"); -// assertEquals("XG__F_21", xnode.getCode()); -// Xnode sameXnode = (Xnode) readNetwork.getDanglingLineStream().findFirst().get().getExtension(Xnode.class); -// assertEquals("XG__F_21", sameXnode.getCode()); -// ConnectablePosition connectablePosition = (ConnectablePosition) readNetwork.getDanglingLineStream().findFirst().get().getExtension(ConnectablePosition.class); -// assertNull(connectablePosition); -// ConnectablePosition connectablePosition2 = (ConnectablePosition) readNetwork.getDanglingLineStream().findFirst().get().getExtensionByName(""); -// assertNull(connectablePosition2); + assertEquals(1, readNetwork.getDanglingLineCount()); + assertEquals("XG__F_21", readNetwork.getDanglingLineStream().findFirst().get().getUcteXnodeCode()); + Xnode xnode = (Xnode) readNetwork.getDanglingLineStream().findFirst().get().getExtensionByName("xnode"); + assertEquals("XG__F_21", xnode.getCode()); + Xnode sameXnode = (Xnode) readNetwork.getDanglingLineStream().findFirst().get().getExtension(Xnode.class); + assertEquals("XG__F_21", sameXnode.getCode()); + ConnectablePosition connectablePosition = (ConnectablePosition) readNetwork.getDanglingLineStream().findFirst().get().getExtension(ConnectablePosition.class); + assertNull(connectablePosition); + ConnectablePosition connectablePosition2 = (ConnectablePosition) readNetwork.getDanglingLineStream().findFirst().get().getExtensionByName(""); + assertNull(connectablePosition2); assertEquals(4, readNetwork.getLineCount()); assertNotNull(readNetwork.getLine("XB__F_21 F_SU1_21 1")); assertNotNull(readNetwork.getLine("XB__F_11 F_SU1_11 1")); diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java index 21ab04bfb..fc8908adc 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java @@ -642,6 +642,18 @@ public ResponseEntity> getDanglingLine( return get(() -> repository.getDanglingLine(networkId, danglingLineId)); } + @DeleteMapping(value = "/{networkId}/dangling-lines/{danglingLineId}", produces = APPLICATION_JSON_VALUE) + @ApiOperation(value = "Delete a dangling line by id", response = Void.class) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successfully get dangling line"), + @ApiResponse(code = 404, message = "Dangling line has not been found") + }) + public ResponseEntity deleteDanglingLine(@ApiParam(value = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @ApiParam(value = "Dangling line ID", required = true) @PathVariable("danglingLineId") String danglingLineId) { + repository.deleteDanglingLine(networkId, danglingLineId); + return ResponseEntity.ok().build(); + } + // buses @PostMapping(value = "/{networkId}/configured-buses") diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java index fb2530521..f3aa492a0 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java @@ -2941,6 +2941,10 @@ public void createDanglingLines(UUID networkUuid, List> resources) { From 92ad9dfb573dc165f963130540acd3c089ef0d33 Mon Sep 17 00:00:00 2001 From: AbdelHedhili Date: Tue, 3 Mar 2020 09:50:23 +0100 Subject: [PATCH 2/8] fix removeDL for PreloadingRestClient Signed-off-by: AbdelHedhili --- .../network/store/client/PreloadingRestNetworkStoreClient.java | 1 - 1 file changed, 1 deletion(-) diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingRestNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingRestNetworkStoreClient.java index 0ccb68daa..508997777 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingRestNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/PreloadingRestNetworkStoreClient.java @@ -514,7 +514,6 @@ public int getDanglingLineCount(UUID networkUuid) { public void removeDanglingLine(UUID networkUuid, String danglingLineId) { restClient.removeDanglingLine(networkUuid, danglingLineId); cacheClient.removeDanglingLine(networkUuid, danglingLineId); - cachedResourceTypes.remove(networkUuid, danglingLineId); } @Override From c4c51c1babc9b7050e899204d3cb0fe33e355ff6 Mon Sep 17 00:00:00 2001 From: AbdelHedhili Date: Tue, 3 Mar 2020 10:02:51 +0100 Subject: [PATCH 3/8] review fix Signed-off-by: AbdelHedhili --- .../com/powsybl/network/store/client/NetworkObjectIndex.java | 1 + 1 file changed, 1 insertion(+) diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkObjectIndex.java b/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkObjectIndex.java index 4b5039a4e..c3e9e6d03 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkObjectIndex.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/NetworkObjectIndex.java @@ -603,6 +603,7 @@ public Identifiable getIdentifiable(String id) { public void removeDanglingLine(String danglingLineId) { storeClient.removeDanglingLine(network.getUuid(), danglingLineId); + danglingLineById.remove(danglingLineId); } //buses From 4cc5016cbc70f6030f8dfb837029cce20fc0ed42 Mon Sep 17 00:00:00 2001 From: AbdelHedhili Date: Tue, 3 Mar 2020 17:28:59 +0100 Subject: [PATCH 4/8] add a buffered deletetion Signed-off-by: AbdelHedhili --- .../BufferedRestNetworkStoreClient.java | 34 ++++++++++++-- .../network/store/client/Resources.java | 9 ++++ .../store/client/RestNetworkStoreClient.java | 6 ++- .../store/integration/NetworkStoreIT.java | 45 +++++++++++++++++++ 4 files changed, 89 insertions(+), 5 deletions(-) diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/BufferedRestNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/BufferedRestNetworkStoreClient.java index f82ec3ac0..426893854 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/BufferedRestNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/BufferedRestNetworkStoreClient.java @@ -45,6 +45,8 @@ public class BufferedRestNetworkStoreClient implements NetworkStoreClient { private final Map>> danglingLineResourcesToFlush = new HashMap<>(); + private final Map> danglingLineToRemove = new HashMap<>(); + private final Map>> twoWindingsTransformerResourcesToFlush = new HashMap<>(); private final Map>> threeWindingsTransformerResourcesToFlush = new HashMap<>(); @@ -445,6 +447,13 @@ public int getHvdcLineCount(UUID networkUuid) { @Override public void createDanglingLines(UUID networkUuid, List> danglingLineResources) { + if (danglingLineToRemove.get(networkUuid) != null) { + int dlToRemoveSize = danglingLineToRemove.size(); + danglingLineResources.forEach(danglingLineResource -> danglingLineToRemove.get(networkUuid).remove(danglingLineResource.getId())); + if (dlToRemoveSize != danglingLineToRemove.size()) { + return; + } + } danglingLineResourcesToFlush.computeIfAbsent(networkUuid, k -> new ArrayList<>()).addAll(danglingLineResources); } @@ -465,10 +474,15 @@ public int getDanglingLineCount(UUID networkUuid) { @Override public void removeDanglingLine(UUID networkUuid, String danglingLineId) { - List> dlToRemove = - danglingLineResourcesToFlush.get(networkUuid).stream().filter(danglingLineAttributesResource -> danglingLineAttributesResource.getId().equals(danglingLineId)).collect(Collectors.toList()); - dlToRemove.forEach(danglingLineAttributesResource -> danglingLineResourcesToFlush.get(networkUuid).remove(danglingLineAttributesResource)); - client.removeDanglingLine(networkUuid, danglingLineId); + if (danglingLineResourcesToFlush.get(networkUuid) != null) { + List> dlToRemove = + danglingLineResourcesToFlush.get(networkUuid).stream().filter(danglingLineAttributesResource -> danglingLineAttributesResource.getId().equals(danglingLineId)).collect(Collectors.toList()); + dlToRemove.forEach(danglingLineAttributesResource -> danglingLineResourcesToFlush.get(networkUuid).remove(danglingLineAttributesResource)); + if (!dlToRemove.isEmpty()) { + return; + } + } + danglingLineToRemove.computeIfAbsent(networkUuid, k -> new ArrayList<>()).add(danglingLineId); } @Override @@ -501,6 +515,16 @@ private static void flushResources(Map> resourcesToDelete, + BiConsumer> deleteFct) { + if (!resourcesToDelete.isEmpty()) { + for (Map.Entry> e : resourcesToDelete.entrySet()) { + deleteFct.accept(e.getKey(), e.getValue()); + } + resourcesToDelete.clear(); + } + } + @Override public void flush() { if (!networkResourcesToFlush.isEmpty()) { @@ -524,5 +548,7 @@ public void flush() { flushResources(threeWindingsTransformerResourcesToFlush, client::createThreeWindingsTransformers); flushResources(lineResourcesToFlush, client::createLines); flushResources(busResourcesToFlush, client::createConfiguredBuses); + + removeResources(danglingLineToRemove, client::removeDanglingLines); } } diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/Resources.java b/network-store-client/src/main/java/com/powsybl/network/store/client/Resources.java index 218c1dade..d7aa47ef9 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/Resources.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/Resources.java @@ -13,8 +13,10 @@ import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.*; import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -53,6 +55,13 @@ public void delete(String url, Object... uriV restTemplate.delete(url, uriVariables); } + public void delete(String url, Map params, Object... uriVariables) { + UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url); + params.forEach(builder::queryParam); + builder.buildAndExpand(uriVariables).toUri(); + restTemplate.delete(builder.toUriString()); + } + public Optional> get(String target, String url, Object... uriVariables) { ResponseEntity> response = getDocument(url, uriVariables); if (response.getStatusCode() == HttpStatus.OK) { diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java index fba0d1593..0ec4f8e0e 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java @@ -506,7 +506,11 @@ public int getDanglingLineCount(UUID networkUuid) { @Override public void removeDanglingLine(UUID networkUuid, String danglingLineId) { - resources.delete("/networks/{networkUuid}/dangling-lines/{danglingLineId}", networkUuid, danglingLineId); + resources.delete("/networks/{networkUuid}/dangling-lines/{danglingLineId}"); + } + + public void removeDanglingLines(UUID networkUuid, List danglingLinesId) { + danglingLinesId.forEach(danglingLineId -> removeDanglingLine(networkUuid, danglingLineId)); } //ConfiguredBus diff --git a/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java b/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java index c39a96189..566870d29 100644 --- a/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java +++ b/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java @@ -765,6 +765,20 @@ public void testUcteNetwork() { } } + @Test + public void testDanglingLineRemove() { + try (NetworkStoreService service = new NetworkStoreService(getBaseUrl())) { + service.flush(createRemoveDL(service.getNetworkFactory())); + } + + try (NetworkStoreService service = new NetworkStoreService(getBaseUrl())) { + Map networkIds = service.getNetworkIds(); + assertEquals(1, networkIds.size()); + Network readNetwork = service.getNetwork(networkIds.keySet().stream().findFirst().get()); + assertEquals(1, readNetwork.getDanglingLineCount()); + } + } + public Network loadUcteNetwork(NetworkFactory networkFactory) { String filePath = "/uctNetwork.uct"; ReadOnlyDataSource dataSource = new ResourceDataSource( @@ -922,4 +936,35 @@ private Network createGeneratorNetwork(NetworkFactory networkFactory, ReactiveLi } return network; } + + private Network createRemoveDL(NetworkFactory networkFactory) { + Network network = networkFactory.createNetwork("DL network", "test"); + Substation s1 = network.newSubstation() + .setId("S1") + .setCountry(Country.ES) + .add(); + VoltageLevel vl1 = s1.newVoltageLevel() + .setId("VL1") + .setNominalV(400f) + .setTopologyKind(TopologyKind.NODE_BREAKER) + .add(); + vl1.newDanglingLine() + .setId("dl1") + .setName("dl1") + .add(); + network.getDanglingLine("dl1").remove(); + vl1.newDanglingLine() + .setId("dl1") + .setName("dl1") + .add(); + vl1.getNodeBreakerView().setNodeCount(2); + vl1.newGenerator() + .setId("GEN") + .setNode(1) + .setMaxP(20) + .setMinP(-20) + .setVoltageRegulatorOn(true) + .add(); + return network; + } } From e1cb0228f480e651b1f5aaba77aa5218312db7a5 Mon Sep 17 00:00:00 2001 From: AbdelHedhili Date: Wed, 4 Mar 2020 10:40:38 +0100 Subject: [PATCH 5/8] fix and increase test coverage Signed-off-by: AbdelHedhili --- .../store/client/RestNetworkStoreClient.java | 6 ++-- .../store/integration/NetworkStoreIT.java | 30 ++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java index 0ec4f8e0e..98eeeebec 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java @@ -506,11 +506,13 @@ public int getDanglingLineCount(UUID networkUuid) { @Override public void removeDanglingLine(UUID networkUuid, String danglingLineId) { - resources.delete("/networks/{networkUuid}/dangling-lines/{danglingLineId}"); + resources.delete("/networks/{networkUuid}/dangling-lines/{danglingLineId}", networkUuid, danglingLineId); } public void removeDanglingLines(UUID networkUuid, List danglingLinesId) { - danglingLinesId.forEach(danglingLineId -> removeDanglingLine(networkUuid, danglingLineId)); + if (!danglingLinesId.isEmpty()) { + danglingLinesId.forEach(danglingLineId -> removeDanglingLine(networkUuid, danglingLineId)); + } } //ConfiguredBus diff --git a/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java b/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java index 566870d29..6d625c822 100644 --- a/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java +++ b/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java @@ -776,6 +776,35 @@ public void testDanglingLineRemove() { assertEquals(1, networkIds.size()); Network readNetwork = service.getNetwork(networkIds.keySet().stream().findFirst().get()); assertEquals(1, readNetwork.getDanglingLineCount()); + service.flush(readNetwork); + } + + try (NetworkStoreService service = new NetworkStoreService(getBaseUrl())) { + Map networkIds = service.getNetworkIds(); + assertEquals(1, networkIds.size()); + Network readNetwork = service.getNetwork(networkIds.keySet().stream().findFirst().get()); + assertEquals(1, readNetwork.getDanglingLineCount()); + readNetwork.getDanglingLine("dl1").remove(); + readNetwork.getVoltageLevel("VL1").newDanglingLine().setName("dl1").setId("dl1").add(); + readNetwork.getVoltageLevel("VL1").newDanglingLine().setName("dl2").setId("dl2").add(); + service.flush(readNetwork); + } + + try (NetworkStoreService service = new NetworkStoreService(getBaseUrl())) { + Map networkIds = service.getNetworkIds(); + assertEquals(1, networkIds.size()); + Network readNetwork = service.getNetwork(networkIds.keySet().stream().findFirst().get()); + assertEquals(2, readNetwork.getDanglingLineCount()); + readNetwork.getDanglingLine("dl2").remove(); + service.flush(readNetwork); + } + + try (NetworkStoreService service = new NetworkStoreService(getBaseUrl())) { + Map networkIds = service.getNetworkIds(); + assertEquals(1, networkIds.size()); + Network readNetwork = service.getNetwork(networkIds.keySet().stream().findFirst().get()); + assertEquals(1, readNetwork.getDanglingLineCount()); + assertNotNull(readNetwork.getDanglingLine("dl1")); } } @@ -957,7 +986,6 @@ private Network createRemoveDL(NetworkFactory networkFactory) { .setId("dl1") .setName("dl1") .add(); - vl1.getNodeBreakerView().setNodeCount(2); vl1.newGenerator() .setId("GEN") .setNode(1) From 4ab61bbfad7a812494ce42c9812b0291f8a16411 Mon Sep 17 00:00:00 2001 From: AbdelHedhili Date: Wed, 4 Mar 2020 15:36:06 +0100 Subject: [PATCH 6/8] remove several DL server side Signed-off-by: AbdelHedhili --- .../network/store/client/Resources.java | 9 +++----- .../store/client/RestNetworkStoreClient.java | 8 ++----- .../store/integration/NetworkStoreIT.java | 1 + .../store/server/NetworkStoreController.java | 16 +++++++++++--- .../store/server/NetworkStoreRepository.java | 21 +++++++++++++++++-- 5 files changed, 38 insertions(+), 17 deletions(-) diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/Resources.java b/network-store-client/src/main/java/com/powsybl/network/store/client/Resources.java index d7aa47ef9..eeb0c1c20 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/Resources.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/Resources.java @@ -51,15 +51,12 @@ public void create(String url, List void delete(String url, Object... uriVariables) { + public void delete(String url, Object... uriVariables) { restTemplate.delete(url, uriVariables); } - public void delete(String url, Map params, Object... uriVariables) { - UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url); - params.forEach(builder::queryParam); - builder.buildAndExpand(uriVariables).toUri(); - restTemplate.delete(builder.toUriString()); + public void deleteAll(String url, Map> params, Object... uriVariables) { + } public Optional> get(String target, String url, Object... uriVariables) { diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java index 98eeeebec..b39a8a579 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/RestNetworkStoreClient.java @@ -16,9 +16,7 @@ import org.springframework.web.client.ResourceAccessException; import org.springframework.web.util.UriComponentsBuilder; -import java.util.List; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import java.util.concurrent.TimeUnit; /** @@ -510,9 +508,7 @@ public void removeDanglingLine(UUID networkUuid, String danglingLineId) { } public void removeDanglingLines(UUID networkUuid, List danglingLinesId) { - if (!danglingLinesId.isEmpty()) { - danglingLinesId.forEach(danglingLineId -> removeDanglingLine(networkUuid, danglingLineId)); - } + danglingLinesId.forEach(danglingLineId -> removeDanglingLine(networkUuid, danglingLineId)); } //ConfiguredBus diff --git a/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java b/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java index 6d625c822..681099d9d 100644 --- a/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java +++ b/network-store-integration-test/src/test/java/com/powsybl/network/store/integration/NetworkStoreIT.java @@ -796,6 +796,7 @@ public void testDanglingLineRemove() { Network readNetwork = service.getNetwork(networkIds.keySet().stream().findFirst().get()); assertEquals(2, readNetwork.getDanglingLineCount()); readNetwork.getDanglingLine("dl2").remove(); + service.flush(readNetwork); } diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java index fc8908adc..f012906ed 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java @@ -643,10 +643,9 @@ public ResponseEntity> getDanglingLine( } @DeleteMapping(value = "/{networkId}/dangling-lines/{danglingLineId}", produces = APPLICATION_JSON_VALUE) - @ApiOperation(value = "Delete a dangling line by id", response = Void.class) + @ApiOperation(value = "Delete a dangling line by id") @ApiResponses(value = { - @ApiResponse(code = 200, message = "Successfully get dangling line"), - @ApiResponse(code = 404, message = "Dangling line has not been found") + @ApiResponse(code = 200, message = "Successfully delete dangling line") }) public ResponseEntity deleteDanglingLine(@ApiParam(value = "Network ID", required = true) @PathVariable("networkId") UUID networkId, @ApiParam(value = "Dangling line ID", required = true) @PathVariable("danglingLineId") String danglingLineId) { @@ -654,6 +653,17 @@ public ResponseEntity deleteDanglingLine(@ApiParam(value = "Network ID", r return ResponseEntity.ok().build(); } + @DeleteMapping(value = "/{networkId}/dangling-lines", produces = APPLICATION_JSON_VALUE) + @ApiOperation(value = "Delete a list of dangling line by id") + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Successfully delete dangling lines") + }) + public ResponseEntity deleteDanglingLines(@ApiParam(value = "Network ID", required = true) @PathVariable("networkId") UUID networkId, + @ApiParam(value = "Dangling line ID", required = true) @RequestParam("danglingLinesId") List danglingLinesId) { + repository.deleteDanglingLines(networkId, danglingLinesId); + return ResponseEntity.ok().build(); + } + // buses @PostMapping(value = "/{networkId}/configured-buses") diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java index f3aa492a0..8f69d2ae2 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java @@ -51,6 +51,8 @@ public class NetworkStoreRepository { private PreparedStatement psInsertDanglingLine; private PreparedStatement psInsertConfiguredBus; + private PreparedStatement psDeleteDanglingLine; + @PostConstruct void prepareStatements() { psInsertNetwork = session.prepare(insertInto(KEYSPACE_IIDM, "network") @@ -348,6 +350,11 @@ void prepareStatements() { .value("properties", bindMarker()) .value("v", bindMarker()) .value("angle", bindMarker())); + + psDeleteDanglingLine = session.prepare( + delete().from("danglingline") + .where(eq("networkUuid", bindMarker())) + .and(eq("id", bindMarker()))); } // This method unsets the null valued columns of a bound statement in order to avoid creation of tombstones @@ -2941,8 +2948,18 @@ public void createDanglingLines(UUID networkUuid, List danglingLinesId) { + for (List subIds : Lists.partition(danglingLinesId, BATCH_SIZE)) { + BatchStatement batch = new BatchStatement(BatchStatement.Type.UNLOGGED); + for (String ids : subIds) { + batch.add(psDeleteDanglingLine.bind(networkUuid, ids)); + } + session.execute(batch); + } } //Buses From 4db3cd68d2036c67ab34b1fcd18fc2a5252aa760 Mon Sep 17 00:00:00 2001 From: AbdelHedhili Date: Wed, 4 Mar 2020 16:25:07 +0100 Subject: [PATCH 7/8] cleanup Signed-off-by: AbdelHedhili --- .../powsybl/network/store/client/Resources.java | 10 +--------- .../store/server/NetworkStoreController.java | 15 +-------------- .../store/server/NetworkStoreRepository.java | 16 ---------------- 3 files changed, 2 insertions(+), 39 deletions(-) diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/Resources.java b/network-store-client/src/main/java/com/powsybl/network/store/client/Resources.java index eeb0c1c20..51997ad60 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/Resources.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/Resources.java @@ -13,12 +13,8 @@ import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.*; import org.springframework.web.client.RestTemplate; -import org.springframework.web.util.UriComponentsBuilder; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; +import java.util.*; /** * @author Geoffroy Jamgotchian @@ -55,10 +51,6 @@ public void delete(String url, Object... uriVariables) { restTemplate.delete(url, uriVariables); } - public void deleteAll(String url, Map> params, Object... uriVariables) { - - } - public Optional> get(String target, String url, Object... uriVariables) { ResponseEntity> response = getDocument(url, uriVariables); if (response.getStatusCode() == HttpStatus.OK) { diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java index f012906ed..92472b682 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreController.java @@ -13,9 +13,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.List; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import java.util.function.Consumer; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -653,17 +651,6 @@ public ResponseEntity deleteDanglingLine(@ApiParam(value = "Network ID", r return ResponseEntity.ok().build(); } - @DeleteMapping(value = "/{networkId}/dangling-lines", produces = APPLICATION_JSON_VALUE) - @ApiOperation(value = "Delete a list of dangling line by id") - @ApiResponses(value = { - @ApiResponse(code = 200, message = "Successfully delete dangling lines") - }) - public ResponseEntity deleteDanglingLines(@ApiParam(value = "Network ID", required = true) @PathVariable("networkId") UUID networkId, - @ApiParam(value = "Dangling line ID", required = true) @RequestParam("danglingLinesId") List danglingLinesId) { - repository.deleteDanglingLines(networkId, danglingLinesId); - return ResponseEntity.ok().build(); - } - // buses @PostMapping(value = "/{networkId}/configured-buses") diff --git a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java index 8f69d2ae2..a248b9281 100644 --- a/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java +++ b/network-store-server/src/main/java/com/powsybl/network/store/server/NetworkStoreRepository.java @@ -51,8 +51,6 @@ public class NetworkStoreRepository { private PreparedStatement psInsertDanglingLine; private PreparedStatement psInsertConfiguredBus; - private PreparedStatement psDeleteDanglingLine; - @PostConstruct void prepareStatements() { psInsertNetwork = session.prepare(insertInto(KEYSPACE_IIDM, "network") @@ -351,10 +349,6 @@ void prepareStatements() { .value("v", bindMarker()) .value("angle", bindMarker())); - psDeleteDanglingLine = session.prepare( - delete().from("danglingline") - .where(eq("networkUuid", bindMarker())) - .and(eq("id", bindMarker()))); } // This method unsets the null valued columns of a bound statement in order to avoid creation of tombstones @@ -2952,16 +2946,6 @@ public void deleteDanglingLine(UUID networkUuid, String danglingLineId) { session.execute(delete().from("danglingLine").where(eq("networkUuid", networkUuid)).and(eq("id", danglingLineId))); } - public void deleteDanglingLines(UUID networkUuid, List danglingLinesId) { - for (List subIds : Lists.partition(danglingLinesId, BATCH_SIZE)) { - BatchStatement batch = new BatchStatement(BatchStatement.Type.UNLOGGED); - for (String ids : subIds) { - batch.add(psDeleteDanglingLine.bind(networkUuid, ids)); - } - session.execute(batch); - } - } - //Buses public void createBuses(UUID networkUuid, List> resources) { From ce56be471428c4d61c7a1df1bf2895ed6aec3de2 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Wed, 25 Mar 2020 11:52:28 +0100 Subject: [PATCH 8/8] Merge Signed-off-by: Geoffroy Jamgotchian --- .../store/client/LazyLoadingRestNetworkStoreClient.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/network-store-client/src/main/java/com/powsybl/network/store/client/LazyLoadingRestNetworkStoreClient.java b/network-store-client/src/main/java/com/powsybl/network/store/client/LazyLoadingRestNetworkStoreClient.java index 5c1c162e5..3746864a1 100644 --- a/network-store-client/src/main/java/com/powsybl/network/store/client/LazyLoadingRestNetworkStoreClient.java +++ b/network-store-client/src/main/java/com/powsybl/network/store/client/LazyLoadingRestNetworkStoreClient.java @@ -423,6 +423,11 @@ public int getDanglingLineCount(UUID networkUuid) { return bufferedRestNetworkStoreClient.getDanglingLineCount(networkUuid); } + @Override + public void removeDanglingLine(UUID networkUuid, String danglingLineId) { + throw new UnsupportedOperationException("TODO"); + } + @Override public void createConfiguredBuses(UUID networkUuid, List> busesRessources) { bufferedRestNetworkStoreClient.createConfiguredBuses(networkUuid, busesRessources);