Skip to content

Commit cf5b029

Browse files
committed
Merge remote-tracking branch 'origin/main' into dbraquart/refacto-use-a-single-entity-for-tabulars
# Conflicts: # pom.xml
2 parents 969e00c + 3503030 commit cf5b029

File tree

5 files changed

+56
-36
lines changed

5 files changed

+56
-36
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<sonar.organization>gridsuite</sonar.organization>
5353
<sonar.projectKey>org.gridsuite:network-modification-server</sonar.projectKey>
5454
<!-- TODO network-modification.version remove when upgrading gridsuite dependencies -->
55-
<network-modification.version>0.39.0-SNAPSHOT</network-modification.version>
55+
<network-modification.version>0.41.0-SNAPSHOT</network-modification.version>
5656
<powsybl-balances-adjustment.version>2.14.1</powsybl-balances-adjustment.version>
5757
</properties>
5858

src/main/java/org/gridsuite/modification/server/elasticsearch/EquipmentInfosService.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package org.gridsuite.modification.server.elasticsearch;
88

99
import com.google.common.collect.Lists;
10+
import com.google.common.collect.Sets;
1011
import com.powsybl.iidm.network.IdentifiableType;
1112
import org.gridsuite.modification.server.dto.elasticsearch.EquipmentInfos;
1213
import org.gridsuite.modification.server.dto.elasticsearch.TombstonedEquipmentInfos;
@@ -38,7 +39,7 @@ public class EquipmentInfosService {
3839
@Value("${spring.data.elasticsearch.partition-size-for-deletion:2048}")
3940
public int partitionSizeForDeletion;
4041

41-
private static final Set<IdentifiableType> TYPES_FOR_INDEXING = Set.of(
42+
private static final Set<IdentifiableType> TYPES_FOR_EQUIPMENT_INDEXING = Set.of(
4243
IdentifiableType.SUBSTATION,
4344
IdentifiableType.VOLTAGE_LEVEL,
4445
IdentifiableType.HVDC_LINE,
@@ -53,8 +54,16 @@ public class EquipmentInfosService {
5354
IdentifiableType.STATIC_VAR_COMPENSATOR,
5455
IdentifiableType.HVDC_CONVERTER_STATION);
5556

57+
private static final Set<IdentifiableType> TYPES_FOR_MODIFICATION_INDEXING = Sets.union(
58+
TYPES_FOR_EQUIPMENT_INDEXING,
59+
Set.of(IdentifiableType.SWITCH, IdentifiableType.BUSBAR_SECTION));
60+
5661
public static Set<IdentifiableType> getIndexedEquipmentTypes() {
57-
return TYPES_FOR_INDEXING;
62+
return TYPES_FOR_EQUIPMENT_INDEXING;
63+
}
64+
65+
public static Set<IdentifiableType> getIndexedEquipmentTypesInModification() {
66+
return TYPES_FOR_MODIFICATION_INDEXING;
5867
}
5968

6069
public EquipmentInfosService(EquipmentInfosRepository equipmentInfosRepository, TombstonedEquipmentInfosRepository tombstonedEquipmentInfosRepository) {

src/main/java/org/gridsuite/modification/server/modifications/NetworkStoreListener.java

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import static org.gridsuite.modification.NetworkModificationException.Type.MODIFICATION_ERROR;
3131
import static org.gridsuite.modification.server.elasticsearch.EquipmentInfosService.getIndexedEquipmentTypes;
32+
import static org.gridsuite.modification.server.elasticsearch.EquipmentInfosService.getIndexedEquipmentTypesInModification;
3233

3334
/**
3435
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
@@ -64,16 +65,12 @@ protected NetworkStoreListener(Network network, UUID networkUuid,
6465
this.collectionThreshold = collectionThreshold;
6566
}
6667

67-
private void updateImpactedEquipment(BasicEquipmentInfos impactedEquipment, SimpleImpactType impactType) {
68-
updateImpactedEquipment(impactedEquipment, impactType, true, true);
69-
}
70-
71-
private void updateImpactedEquipment(BasicEquipmentInfos impactedEquipment, SimpleImpactType impactType, boolean indexEquipment, boolean indexInModification) {
68+
private void updateImpactedEquipment(BasicEquipmentInfos impactedEquipment, SimpleImpactType impactType, boolean shouldIndexEquipment, boolean shouldIndexModification) {
7269
ImpactedEquipmentsInfos infosToUpdate = modificationApplicationInfosList.getLast().getImpactedEquipmentsInfos();
7370
switch (impactType) {
74-
case CREATION -> infosToUpdate.getCreatedEquipments().add(new IndexedImpactedEquipmentInfos<>((EquipmentInfos) impactedEquipment, indexEquipment, indexInModification));
75-
case MODIFICATION -> infosToUpdate.getModifiedEquipments().add(new IndexedImpactedEquipmentInfos<>((EquipmentInfos) impactedEquipment, indexEquipment, indexInModification));
76-
case DELETION -> infosToUpdate.getTombstonedEquipments().add(new IndexedImpactedEquipmentInfos<>((TombstonedEquipmentInfos) impactedEquipment, indexEquipment, indexInModification));
71+
case CREATION -> infosToUpdate.getCreatedEquipments().add(new IndexedImpactedEquipmentInfos<>((EquipmentInfos) impactedEquipment, shouldIndexEquipment, shouldIndexModification));
72+
case MODIFICATION -> infosToUpdate.getModifiedEquipments().add(new IndexedImpactedEquipmentInfos<>((EquipmentInfos) impactedEquipment, shouldIndexEquipment, shouldIndexModification));
73+
case DELETION -> infosToUpdate.getTombstonedEquipments().add(new IndexedImpactedEquipmentInfos<>((TombstonedEquipmentInfos) impactedEquipment, shouldIndexEquipment, shouldIndexModification));
7774
}
7875
}
7976

@@ -123,43 +120,51 @@ private void addSimpleModificationImpact(Identifiable<?> identifiable) {
123120
@Override
124121
public void onPropertyRemoved(Identifiable identifiable, String attribute, Object oldValue) {
125122
addSimpleModificationImpact(identifiable);
126-
if (getIndexedEquipmentTypes().contains(identifiable.getType())) {
127-
updateEquipmentIndexation(identifiable, attribute, networkUuid, network.getVariantManager().getWorkingVariantId());
128-
}
123+
updateEquipmentIndexation(identifiable, attribute, networkUuid, network.getVariantManager().getWorkingVariantId());
129124
}
130125

131126
@Override
132127
public void onPropertyAdded(Identifiable identifiable, String attribute, Object newValue) {
133128
addSimpleModificationImpact(identifiable);
134-
if (getIndexedEquipmentTypes().contains(identifiable.getType())) {
135-
updateEquipmentIndexation(identifiable, attribute, networkUuid, network.getVariantManager().getWorkingVariantId());
136-
}
129+
updateEquipmentIndexation(identifiable, attribute, networkUuid, network.getVariantManager().getWorkingVariantId());
137130
}
138131

139132
@Override
140133
public void onPropertyReplaced(Identifiable identifiable, String attribute, Object oldValue, Object newValue) {
141134
addSimpleModificationImpact(identifiable);
142-
if (getIndexedEquipmentTypes().contains(identifiable.getType())) {
135+
boolean shouldIndexEquipment = getIndexedEquipmentTypes().contains(identifiable.getType());
136+
boolean shouldIndexModification = getIndexedEquipmentTypesInModification().contains(identifiable.getType());
137+
if (shouldIndexEquipment || shouldIndexModification) {
143138
updateEquipmentIndexation(identifiable, attribute, networkUuid, network.getVariantManager().getWorkingVariantId());
144139
}
145140
}
146141

147142
@Override
148143
public void onUpdate(Identifiable identifiable, String attribute, String variantId, Object oldValue, Object newValue) {
149144
addSimpleModificationImpact(identifiable);
150-
if (getIndexedEquipmentTypes().contains(identifiable.getType())) {
145+
if (getIndexedEquipmentTypesInModification().contains(identifiable.getType())) {
151146
updateEquipmentIndexation(identifiable, attribute, networkUuid, network.getVariantManager().getWorkingVariantId());
152147
}
153148
}
154149

155150
private void updateEquipmentIndexation(Identifiable<?> identifiable, String attribute, UUID networkUuid, String variantId) {
156151
// Equipments should be indexed in equipment index only if equipment name has been updated
157-
boolean shouldIndexEquipments = attribute.equals("name");
158-
updateImpactedEquipment(toEquipmentInfos(identifiable, networkUuid, variantId), SimpleImpactType.MODIFICATION, shouldIndexEquipments, true);
152+
boolean shouldIndexEquipment = getIndexedEquipmentTypes().contains(identifiable.getType()) && "name".equals(attribute);
153+
boolean shouldIndexModification = getIndexedEquipmentTypesInModification().contains(identifiable.getType());
154+
155+
updateImpactedEquipment(
156+
toEquipmentInfos(identifiable, networkUuid, variantId),
157+
SimpleImpactType.MODIFICATION,
158+
shouldIndexEquipment,
159+
shouldIndexModification
160+
);
161+
159162
// If the updated attribute is "name" and the identifiable is a VOLTAGE_LEVEL or SUBSTATION,
160163
// we must update all linked equipment in equipment index to reflect the name change
161164
// modification index is not updated here
162-
if (shouldIndexEquipments && (identifiable.getType().equals(IdentifiableType.VOLTAGE_LEVEL) || identifiable.getType().equals(IdentifiableType.SUBSTATION))) {
165+
if (shouldIndexEquipment
166+
&& (identifiable.getType().equals(IdentifiableType.VOLTAGE_LEVEL)
167+
|| identifiable.getType().equals(IdentifiableType.SUBSTATION))) {
163168
updateLinkedEquipments(identifiable);
164169
}
165170
}
@@ -196,7 +201,9 @@ private void updateEquipmentsLinkedToVoltageLevel(VoltageLevel voltageLevel) {
196201

197202
@Override
198203
public void onCreation(Identifiable identifiable) {
199-
if (getIndexedEquipmentTypes().contains(identifiable.getType())) {
204+
boolean shouldIndexEquipment = getIndexedEquipmentTypes().contains(identifiable.getType());
205+
boolean shouldIndexModification = getIndexedEquipmentTypesInModification().contains(identifiable.getType());
206+
if (shouldIndexEquipment || shouldIndexModification) {
200207
updateImpactedEquipment(EquipmentInfos.builder()
201208
.networkUuid(networkUuid)
202209
.variantId(network.getVariantManager().getWorkingVariantId())
@@ -205,7 +212,7 @@ public void onCreation(Identifiable identifiable) {
205212
.type(EquipmentInfos.getEquipmentTypeName(identifiable))
206213
.voltageLevels(EquipmentInfos.getVoltageLevelsInfos(identifiable))
207214
.substations(EquipmentInfos.getSubstationsInfos(identifiable))
208-
.build(), SimpleImpactType.CREATION);
215+
.build(), SimpleImpactType.CREATION, shouldIndexEquipment, shouldIndexModification);
209216
}
210217
simpleImpacts.add(
211218
SimpleElementImpact.builder()
@@ -219,13 +226,14 @@ public void onCreation(Identifiable identifiable) {
219226

220227
@Override
221228
public void beforeRemoval(Identifiable identifiable) {
222-
if (getIndexedEquipmentTypes().contains(identifiable.getType())) {
223-
updateImpactedEquipment(TombstonedEquipmentInfos.builder()
229+
boolean shouldIndexEquipment = getIndexedEquipmentTypes().contains(identifiable.getType());
230+
boolean shouldIndexModification = getIndexedEquipmentTypesInModification().contains(identifiable.getType());
231+
updateImpactedEquipment(TombstonedEquipmentInfos.builder()
224232
.networkUuid(networkUuid)
225233
.variantId(network.getVariantManager().getWorkingVariantId())
226234
.id(identifiable.getId())
227-
.build(), SimpleImpactType.DELETION);
228-
}
235+
.build(), SimpleImpactType.DELETION, shouldIndexEquipment, shouldIndexModification);
236+
229237
simpleImpacts.add(
230238
SimpleElementImpact.builder()
231239
.simpleImpactType(SimpleImpactType.DELETION)
@@ -390,9 +398,10 @@ private List<EquipmentInfos> getAllModifiedEquipmentsToBeIndexed() {
390398
@Override
391399
public void onExtensionCreation(Extension<?> extension) {
392400
Identifiable<?> identifiable = (Identifiable<?>) extension.getExtendable();
393-
if (getIndexedEquipmentTypes().contains(identifiable.getType())) {
394-
updateImpactedEquipment(toEquipmentInfos(identifiable, networkUuid, network.getVariantManager().getWorkingVariantId()), SimpleImpactType.MODIFICATION);
395-
}
401+
boolean shouldIndexEquipment = getIndexedEquipmentTypes().contains(identifiable.getType());
402+
boolean shouldIndexModification = getIndexedEquipmentTypesInModification().contains(identifiable.getType());
403+
updateImpactedEquipment(toEquipmentInfos(identifiable, networkUuid, network.getVariantManager().getWorkingVariantId()), SimpleImpactType.MODIFICATION, shouldIndexEquipment, shouldIndexModification);
404+
396405
addSimpleModificationImpact(identifiable);
397406
}
398407

src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ void testSearchModificationInfos() throws Exception {
19791979
});
19801980
assertEquals(1, networkModificationsResult.size());
19811981
modificationsSearchResult = networkModificationsResult.get(TEST_GROUP_ID);
1982-
assertEquals(1, modificationsSearchResult.size());
1982+
assertEquals(4, modificationsSearchResult.size());
19831983
assertEquals("GENERATOR_CREATION", modificationsSearchResult.getFirst().getMessageType());
19841984
assertEquals("{\"equipmentId\":\"idGenerator1\"}", modificationsSearchResult.getFirst().getMessageValues());
19851985

src/test/java/org/gridsuite/modification/server/service/ModificationIndexationTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void testApplyCreatingModifications() {
124124
assertEquals(entities.getFirst().getId(), modificationApplicationEntities.getFirst().getModification().getId());
125125
assertEquals(entities.getFirst().getId(), modificationApplicationInfos.getFirst().getModificationUuid());
126126
assertEquals(groupUuid, modificationApplicationInfos.getFirst().getGroupUuid());
127-
assertEquals(newEquipmentId, modificationApplicationInfos.getFirst().getCreatedEquipmentIds().iterator().next());
127+
assertTrue(modificationApplicationInfos.getFirst().getCreatedEquipmentIds().contains(newEquipmentId));
128128
}
129129

130130
@Test
@@ -174,7 +174,7 @@ void testApplyDeletingModifications() {
174174
assertEquals(entities.getFirst().getId(), modificationApplicationEntities.getFirst().getModification().getId());
175175
assertEquals(entities.getFirst().getId(), modificationApplicationInfos.getFirst().getModificationUuid());
176176
assertEquals(groupUuid, modificationApplicationInfos.getFirst().getGroupUuid());
177-
assertEquals(deletedEquipmentId, modificationApplicationInfos.getFirst().getDeletedEquipmentIds().iterator().next());
177+
assertTrue(modificationApplicationInfos.getFirst().getDeletedEquipmentIds().contains(deletedEquipmentId));
178178
}
179179

180180
@Test
@@ -217,7 +217,9 @@ void testDuplicateModifications() {
217217
assertThat(modificationApplicationInfos.stream().map(ModificationApplicationInfos::getModificationUuid).toList()).usingRecursiveComparison().isEqualTo(expectedModificationUuids);
218218

219219
assertThat(modificationApplicationInfos.stream().map(ModificationApplicationInfos::getGroupUuid).toList()).usingRecursiveComparison().isEqualTo(expectedGroupUuids);
220-
modificationApplicationInfos.forEach(applicationInfo -> assertEquals(newEquipmentId, applicationInfo.getCreatedEquipmentIds().iterator().next()));
220+
modificationApplicationInfos.forEach(applicationInfo ->
221+
assertTrue(applicationInfo.getCreatedEquipmentIds().contains(newEquipmentId))
222+
);
221223
}
222224

223225
@Test
@@ -262,7 +264,7 @@ void testMoveModifications() {
262264
assertThat(modificationApplicationInfos.stream().map(ModificationApplicationInfos::getModificationUuid).toList()).usingRecursiveComparison().isEqualTo(expectedModificationUuids);
263265

264266
assertThat(modificationApplicationInfos.stream().map(ModificationApplicationInfos::getGroupUuid).toList()).usingRecursiveComparison().isEqualTo(expectedGroupUuids);
265-
modificationApplicationInfos.forEach(applicationInfo -> assertEquals(newEquipmentId, applicationInfo.getCreatedEquipmentIds().iterator().next()));
267+
modificationApplicationInfos.forEach(applicationInfo -> assertTrue(applicationInfo.getCreatedEquipmentIds().contains(newEquipmentId)));
266268
}
267269

268270
@Test

0 commit comments

Comments
 (0)