Skip to content

Commit

Permalink
fix: PR remarks
Browse files Browse the repository at this point in the history
Signed-off-by: LE SAULNIER Kevin <[email protected]>
  • Loading branch information
LE SAULNIER Kevin committed Nov 30, 2023
1 parent 7abf4d9 commit 8b33e6f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public interface EquipmentInfosRepository extends ElasticsearchRepository<Equipm

List<EquipmentInfos> findByIdInAndNetworkUuidAndVariantId(@NonNull List<String> 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<String> equipmentIds, @NonNull UUID networkUuid, @NonNull String variantId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class NetworkStoreListener implements NetworkListener {

private final List<EquipmentInfos> createdEquipments = new ArrayList<>();

private final List<EquipmentInfos> modifiedEquipments = new ArrayList<>();

private final Set<SimpleElementImpact> networkImpacts = new LinkedHashSet<>();

// TODO : Move to the NetworkModificationApplicator class
Expand Down Expand Up @@ -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());
}

Expand All @@ -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))) {
Expand All @@ -155,31 +151,35 @@ private void updateLinkedEquipments(Identifiable<?> identifiable) {
// update substation linked to voltageLevel
Optional<Substation> 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<VoltageLevel> 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<VoltageLevel> 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()))
);
}

Expand Down Expand Up @@ -261,5 +261,6 @@ private void flushEquipmentInfos() {
equipmentInfosService.deleteEquipmentInfosList(equipmentDeletionsIds, networkUuid, variantId);
equipmentInfosService.addAllTombstonedEquipmentInfos(tombstonedEquipmentInfos);
equipmentInfosService.addAllEquipmentInfos(createdEquipments);
equipmentInfosService.addAllEquipmentInfos(modifiedEquipments);
}
}

0 comments on commit 8b33e6f

Please sign in to comment.