diff --git a/src/main/java/org/gridsuite/modification/server/dto/elasticsearch/EquipmentInfos.java b/src/main/java/org/gridsuite/modification/server/dto/elasticsearch/EquipmentInfos.java index 66444215a..9c58eb8be 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/elasticsearch/EquipmentInfos.java +++ b/src/main/java/org/gridsuite/modification/server/dto/elasticsearch/EquipmentInfos.java @@ -132,4 +132,16 @@ public static EquipmentInfos toInfosWithUpdatedSubstationName(Identifiable li .voltageLevels(EquipmentInfos.getVoltageLevelsInfos(linkedEquipment)) .build(); } + + public static EquipmentInfos toInfos(Identifiable identifiable, UUID networkUuid, String variantId) { + return EquipmentInfos.builder() + .networkUuid(networkUuid) + .variantId(variantId) + .id(identifiable.getId()) + .name(identifiable.getNameOrId()) + .type(identifiable.getType().name()) + .voltageLevels(EquipmentInfos.getVoltageLevelsInfos(identifiable)) + .substations(EquipmentInfos.getSubstationsInfos(identifiable)) + .build(); + } } diff --git a/src/main/java/org/gridsuite/modification/server/elasticsearch/EquipmentInfosRepository.java b/src/main/java/org/gridsuite/modification/server/elasticsearch/EquipmentInfosRepository.java index c13ed2447..82cf44e7f 100644 --- a/src/main/java/org/gridsuite/modification/server/elasticsearch/EquipmentInfosRepository.java +++ b/src/main/java/org/gridsuite/modification/server/elasticsearch/EquipmentInfosRepository.java @@ -21,8 +21,6 @@ public interface EquipmentInfosRepository extends ElasticsearchRepository findByIdInAndNetworkUuidAndVariantId(@NonNull List equipmentIds, @NonNull UUID networkUuid, @NonNull String variantId); - EquipmentInfos findByIdAndNetworkUuid/*AndVariantId*/(@NonNull String equipmentId, @NonNull UUID networkUuid/*, @NonNull String variantId*/); - void deleteAllByNetworkUuidAndVariantId(UUID networkUuid, String variantId); void deleteByIdInAndNetworkUuidAndVariantId(@NonNull List equipmentIds, @NonNull UUID networkUuid, @NonNull String variantId); diff --git a/src/main/java/org/gridsuite/modification/server/elasticsearch/EquipmentInfosService.java b/src/main/java/org/gridsuite/modification/server/elasticsearch/EquipmentInfosService.java index 02de9fa4c..d883a74dc 100644 --- a/src/main/java/org/gridsuite/modification/server/elasticsearch/EquipmentInfosService.java +++ b/src/main/java/org/gridsuite/modification/server/elasticsearch/EquipmentInfosService.java @@ -7,7 +7,6 @@ package org.gridsuite.modification.server.elasticsearch; import com.google.common.collect.Lists; -import com.powsybl.iidm.network.Identifiable; import org.gridsuite.modification.server.dto.elasticsearch.EquipmentInfos; import org.gridsuite.modification.server.dto.elasticsearch.TombstonedEquipmentInfos; import org.springframework.beans.factory.annotation.Value; @@ -89,18 +88,4 @@ public void deleteAll() { equipmentInfosRepository.deleteAll(); tombstonedEquipmentInfosRepository.deleteAll(); } - - public void updateEquipment(Identifiable identifiable, UUID networkUuid, String variantId) { - EquipmentInfos equipmentToUpdate = EquipmentInfos.builder() - .networkUuid(networkUuid) - .variantId(variantId) - .id(identifiable.getId()) - .name(identifiable.getNameOrId()) - .type(identifiable.getType().name()) - .voltageLevels(EquipmentInfos.getVoltageLevelsInfos(identifiable)) - .substations(EquipmentInfos.getSubstationsInfos(identifiable)) - .build(); - - equipmentInfosRepository.save(equipmentToUpdate); - } } 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 165f7024d..2211d9b4a 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/NetworkStoreListener.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/NetworkStoreListener.java @@ -41,6 +41,8 @@ public class NetworkStoreListener implements NetworkListener { private final List createdEquipments = new ArrayList<>(); + private final List modifiedEquipments = new ArrayList<>(); + private final Set networkImpacts = new LinkedHashSet<>(); // TODO : Move to the NetworkModificationApplicator class @@ -121,14 +123,7 @@ public void onElementReplaced(Identifiable identifiable, String attribute, Objec @Override public void onUpdate(Identifiable identifiable, String attribute, Object oldValue, Object newValue) { - networkImpacts.add( - SimpleElementImpact.builder() - .impactType(SimpleElementImpact.SimpleImpactType.MODIFICATION) - .elementType(identifiable.getType()) - .elementId(identifiable.getId()) - .substationIds(getSubstationIds(identifiable)) - .build() - ); + addSimpleModificationImpact(identifiable); updateEquipmentIndexation(identifiable, attribute, networkUuid, network.getVariantManager().getWorkingVariantId()); } @@ -139,7 +134,8 @@ public void onUpdate(Identifiable identifiable, String attribute, String variant } private void updateEquipmentIndexation(Identifiable identifiable, String attribute, UUID networkUuid, String variantId) { - equipmentInfosService.updateEquipment(identifiable, networkUuid, variantId); + modifiedEquipments.add(EquipmentInfos.toInfos(identifiable, networkUuid, variantId)); + // because all each equipment carry its linked voltage levels/substations name within its document // if attribute is "name" and identifiable type is VOLTAGE_LEVEL or SUBSTATION, we need to update all equipments linked to it if (attribute.equals("name") && (identifiable.getType().equals(IdentifiableType.VOLTAGE_LEVEL) || identifiable.getType().equals(IdentifiableType.SUBSTATION))) { @@ -155,31 +151,35 @@ private void updateLinkedEquipments(Identifiable identifiable) { // update substation linked to voltageLevel Optional linkedSubstation = updatedVoltageLevel.getSubstation(); if (linkedSubstation.isPresent()) { - createdEquipments.add(EquipmentInfos.toInfosWithUpdatedVoltageLevelName(linkedSubstation.get(), updatedVoltageLevel, networkUuid, network.getVariantManager().getWorkingVariantId())); + modifiedEquipments.add(EquipmentInfos.toInfosWithUpdatedVoltageLevelName(linkedSubstation.get(), updatedVoltageLevel, networkUuid, network.getVariantManager().getWorkingVariantId())); } } else if (identifiable.getType().equals(IdentifiableType.SUBSTATION)) { Substation updatedSubstation = network.getSubstation(identifiable.getId()); - Iterable linkedVoltageLevels = updatedSubstation.getVoltageLevels(); - // update all voltageLevels linked to substation - linkedVoltageLevels.forEach(vl -> createdEquipments.add(EquipmentInfos.toInfosWithUpdatedSubstationName(vl, updatedSubstation, networkUuid, network.getVariantManager().getWorkingVariantId()))); - // update all equipments linked to each of the voltageLevels - linkedVoltageLevels.forEach(vl -> - Iterables.concat( - vl.getConnectables(), - vl.getSwitches() - ).forEach(c -> - createdEquipments.add(EquipmentInfos.toInfosWithUpdatedSubstationName(c, updatedSubstation, networkUuid, network.getVariantManager().getWorkingVariantId())) - ) - ); + updateEquipmentsLinkedToSubstation(updatedSubstation); } } + private void updateEquipmentsLinkedToSubstation(Substation substation) { + Iterable linkedVoltageLevels = substation.getVoltageLevels(); + // update all voltageLevels linked to substation + linkedVoltageLevels.forEach(vl -> modifiedEquipments.add(EquipmentInfos.toInfosWithUpdatedSubstationName(vl, substation, networkUuid, network.getVariantManager().getWorkingVariantId()))); + // update all equipments linked to each of the voltageLevels + linkedVoltageLevels.forEach(vl -> + Iterables.concat( + vl.getConnectables(), + vl.getSwitches() + ).forEach(c -> + modifiedEquipments.add(EquipmentInfos.toInfosWithUpdatedSubstationName(c, substation, networkUuid, network.getVariantManager().getWorkingVariantId())) + ) + ); + } + private void updateEquipmentsLinkedToVoltageLevel(VoltageLevel voltageLevel) { Iterables.concat( voltageLevel.getConnectables(), voltageLevel.getSwitches() ).forEach(c -> - createdEquipments.add(EquipmentInfos.toInfosWithUpdatedVoltageLevelName(c, voltageLevel, networkUuid, network.getVariantManager().getWorkingVariantId())) + modifiedEquipments.add(EquipmentInfos.toInfosWithUpdatedVoltageLevelName(c, voltageLevel, networkUuid, network.getVariantManager().getWorkingVariantId())) ); } @@ -261,5 +261,6 @@ private void flushEquipmentInfos() { equipmentInfosService.deleteEquipmentInfosList(equipmentDeletionsIds, networkUuid, variantId); equipmentInfosService.addAllTombstonedEquipmentInfos(tombstonedEquipmentInfos); equipmentInfosService.addAllEquipmentInfos(createdEquipments); + equipmentInfosService.addAllEquipmentInfos(modifiedEquipments); } }