2929
3030import static org .gridsuite .modification .NetworkModificationException .Type .MODIFICATION_ERROR ;
3131import 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
0 commit comments