From ebe56ce34e4167b915846db233b51f42d7cb910d Mon Sep 17 00:00:00 2001 From: FranckLecuyer <47824306+FranckLecuyer@users.noreply.github.com> Date: Wed, 15 Jan 2025 10:55:16 +0100 Subject: [PATCH] upgrade to gridsuite dependencies 36 and network modification 0.5.0 (#583) * upgrade to gridsuite dependencies 36 * use new network-modification release 0.5.0 Signed-off-by: Franck LECUYER --- pom.xml | 19 +------ .../modifications/NetworkStoreListener.java | 29 ++++++---- .../service/NetworkVariantsListener.java | 33 ++++++++--- .../service/NetworkVariantsListenerTests.java | 56 +++++++++++++++++++ 4 files changed, 101 insertions(+), 36 deletions(-) create mode 100644 src/test/java/org/gridsuite/modification/server/service/NetworkVariantsListenerTests.java diff --git a/pom.xml b/pom.xml index 5525dff14..c0641b208 100644 --- a/pom.xml +++ b/pom.xml @@ -44,18 +44,12 @@ - 35 + 36 1.0.5 5.0.0-alpha.14 org.gridsuite.modification.server **/migration/**/* - 0.4.0 - - 1.0.16 - - - 1.18.0 + 0.5.0 @@ -98,13 +92,6 @@ pom import - - - org.gridsuite - gridsuite-filter - ${filter.version} - @@ -146,8 +133,6 @@ com.powsybl powsybl-ws-commons - - ${powsybl-ws-commons.version} org.projectlombok diff --git a/src/main/java/org/gridsuite/modification/server/modifications/NetworkStoreListener.java b/src/main/java/org/gridsuite/modification/server/modifications/NetworkStoreListener.java index 40a2b08d2..e155587dc 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/NetworkStoreListener.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/NetworkStoreListener.java @@ -104,26 +104,20 @@ private void addSimpleModificationImpact(Identifiable identifiable) { } @Override - public void onElementRemoved(Identifiable identifiable, String attribute, Object oldValue) { + public void onPropertyRemoved(Identifiable identifiable, String attribute, Object oldValue) { addSimpleModificationImpact(identifiable); } @Override - public void onElementAdded(Identifiable identifiable, String attribute, Object newValue) { + public void onPropertyAdded(Identifiable identifiable, String attribute, Object newValue) { addSimpleModificationImpact(identifiable); } @Override - public void onElementReplaced(Identifiable identifiable, String attribute, Object oldValue, Object newValue) { + public void onPropertyReplaced(Identifiable identifiable, String attribute, Object oldValue, Object newValue) { addSimpleModificationImpact(identifiable); } - @Override - public void onUpdate(Identifiable identifiable, String attribute, Object oldValue, Object newValue) { - addSimpleModificationImpact(identifiable); - updateEquipmentIndexation(identifiable, attribute, networkUuid, network.getVariantManager().getWorkingVariantId()); - } - @Override public void onUpdate(Identifiable identifiable, String attribute, String variantId, Object oldValue, Object newValue) { addSimpleModificationImpact(identifiable); @@ -337,8 +331,23 @@ public void onExtensionBeforeRemoval(Extension extension) { } @Override - public void onExtensionUpdate(Extension extendable, String attribute, Object oldValue, Object newValue) { + public void onExtensionUpdate(Extension extendable, String attribute, String variantId, Object oldValue, Object newValue) { + Identifiable identifiable = (Identifiable) extendable.getExtendable(); + onUpdate(identifiable, attribute, variantId, oldValue, newValue); + } + + @Override + public void onVariantCreated(String sourceVariantId, String targetVariantId) { // FIXME: implement this method } + @Override + public void onVariantOverwritten(String sourceVariantId, String targetVariantId) { + // FIXME: implement this method + } + + @Override + public void onVariantRemoved(String variantId) { + // FIXME: implement this method + } } diff --git a/src/main/java/org/gridsuite/modification/server/service/NetworkVariantsListener.java b/src/main/java/org/gridsuite/modification/server/service/NetworkVariantsListener.java index 938a17aa9..30b098a18 100644 --- a/src/main/java/org/gridsuite/modification/server/service/NetworkVariantsListener.java +++ b/src/main/java/org/gridsuite/modification/server/service/NetworkVariantsListener.java @@ -46,10 +46,6 @@ public void beforeRemoval(Identifiable identifiable) { public void afterRemoval(String s) { } - @Override - public void onUpdate(Identifiable identifiable, String attribute, Object oldValue, Object newValue) { - } - @Override public void onVariantCreated(String sourceVariantId, String targetVariantId) { // Initial variant modifications are not cloned @@ -64,13 +60,18 @@ public void onVariantRemoved(String variantId) { } @Override - public void onUpdate(Identifiable identifiable, String attribute, String variantId, Object oldValue, - Object newValue) { + public void onVariantOverwritten(String sourceVariantId, String targetVariantId) { + equipmentInfosService.deleteVariants(networkUuid, List.of(targetVariantId)); + onVariantCreated(sourceVariantId, targetVariantId); + } + + @Override + public void onUpdate(Identifiable identifiable, String attribute, String variantId, Object oldValue, Object newValue) { // do nothing } @Override - public void onExtensionCreation(Extension extension) { + public void onExtensionBeforeRemoval(Extension extension) { // do nothing } @@ -80,13 +81,27 @@ public void onExtensionAfterRemoval(Identifiable identifiable, String extensi } @Override - public void onExtensionBeforeRemoval(Extension extension) { + public void onExtensionUpdate(Extension extendable, String attribute, String variantId, Object oldValue, Object newValue) { // do nothing } @Override - public void onExtensionUpdate(Extension extendable, String attribute, Object oldValue, Object newValue) { + public void onExtensionCreation(Extension extension) { // do nothing } + @Override + public void onPropertyAdded(Identifiable identifiable, String attribute, Object newValue) { + // do nothing + } + + @Override + public void onPropertyReplaced(Identifiable identifiable, String attribute, Object oldValue, Object newValue) { + // do nothing + } + + @Override + public void onPropertyRemoved(Identifiable identifiable, String attribute, Object oldValue) { + // do nothing + } } diff --git a/src/test/java/org/gridsuite/modification/server/service/NetworkVariantsListenerTests.java b/src/test/java/org/gridsuite/modification/server/service/NetworkVariantsListenerTests.java new file mode 100644 index 000000000..f1a350f22 --- /dev/null +++ b/src/test/java/org/gridsuite/modification/server/service/NetworkVariantsListenerTests.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.gridsuite.modification.server.service; + +import org.gridsuite.modification.server.elasticsearch.EquipmentInfosService; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.elasticsearch.NoSuchIndexException; + +import java.util.List; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; + + +/** + * @author Franck Lecuyer + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) +class NetworkVariantsListenerTests { + private static final UUID NETWORK_UUID = UUID.randomUUID(); + private static final String VARIANT_ID = "variant_1"; + + @Autowired + private EquipmentInfosService equipmentInfosService; + + @AfterEach + void tearDown() { + try { + equipmentInfosService.deleteAll(); + } catch (NoSuchIndexException ex) { + // no need to worry that much + } + } + + @Test + void testVariantNotifications() { + NetworkVariantsListener listener = new NetworkVariantsListener(null, NETWORK_UUID, equipmentInfosService); + + listener.onVariantRemoved(VARIANT_ID); + listener.onVariantCreated("variant_1", "variant_2"); + assertEquals(0, equipmentInfosService.findEquipmentInfosList(List.of("equipment1", "equipment2"), NETWORK_UUID, "variant_2").size()); + listener.onVariantOverwritten("variant_2", "variant_3"); + listener.onUpdate(null, null, null, null, null); + listener.onExtensionUpdate(null, null, null, null, null); + listener.onPropertyAdded(null, null, null); + listener.onPropertyReplaced(null, null, null, null); + listener.onPropertyRemoved(null, null, null); + } +}