Skip to content

Commit 8747506

Browse files
refactor: call to network modification applicator
Signed-off-by: Joris Mancini <joris.mancini_externe@rte-france.com>
1 parent 8de14b7 commit 8747506

19 files changed

+485
-453
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
package org.gridsuite.modification.server;
9+
10+
import com.powsybl.iidm.modification.topology.DefaultNamingStrategy;
11+
import com.powsybl.iidm.modification.topology.NamingStrategiesServiceLoader;
12+
import com.powsybl.iidm.modification.topology.NamingStrategy;
13+
import org.springframework.beans.factory.annotation.Value;
14+
import org.springframework.context.annotation.Bean;
15+
import org.springframework.context.annotation.Configuration;
16+
17+
/**
18+
* @author Joris Mancini <joris.mancini_externe at rte-france.com>
19+
*/
20+
@Configuration
21+
public class NamingStrategyConfiguration {
22+
23+
private final NamingStrategiesServiceLoader namingStrategiesServiceLoader = new NamingStrategiesServiceLoader();
24+
25+
@Value("${naming-strategy:Default}")
26+
private String namingStrategy;
27+
28+
@Bean
29+
public NamingStrategy getNamingStrategy() {
30+
return namingStrategiesServiceLoader.findNamingStrategyByName(namingStrategy).orElse(new DefaultNamingStrategy());
31+
}
32+
}

src/main/java/org/gridsuite/modification/server/dto/NetworkInfos.java

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
package org.gridsuite.modification.server.modifications;
9+
10+
import com.powsybl.iidm.network.Network;
11+
import org.gridsuite.modification.server.entities.ModificationEntity;
12+
import org.gridsuite.modification.server.impacts.AbstractBaseImpact;
13+
14+
import java.util.List;
15+
import java.util.UUID;
16+
17+
/**
18+
* @author Joris Mancini <joris.mancini_externe at rte-france.com>
19+
*/
20+
public record ModificationNetwork(
21+
UUID networkUuid,
22+
Network network,
23+
NetworkStoreListener networkStoreListener
24+
) {
25+
26+
public List<AbstractBaseImpact> flush() {
27+
return networkStoreListener.flushModificationApplications();
28+
}
29+
30+
public void initModificationApplication(UUID groupUuid, ModificationEntity modification) {
31+
networkStoreListener.initModificationApplication(groupUuid, modification);
32+
}
33+
}
34+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
package org.gridsuite.modification.server.modifications;
9+
10+
import com.powsybl.commons.PowsyblException;
11+
import com.powsybl.iidm.network.Network;
12+
import com.powsybl.network.store.client.NetworkStoreService;
13+
import com.powsybl.network.store.client.PreloadingStrategy;
14+
import org.gridsuite.modification.NetworkModificationException;
15+
import org.gridsuite.modification.server.elasticsearch.EquipmentInfosService;
16+
import org.gridsuite.modification.server.elasticsearch.ModificationApplicationInfosService;
17+
import org.gridsuite.modification.server.service.NetworkVariantsListener;
18+
import org.springframework.beans.factory.annotation.Value;
19+
import org.springframework.stereotype.Service;
20+
21+
import java.util.UUID;
22+
23+
import static org.gridsuite.modification.NetworkModificationException.Type.NETWORK_NOT_FOUND;
24+
25+
/**
26+
* @author Joris Mancini <joris.mancini_externe at rte-france.com>
27+
*/
28+
@Service
29+
public class ModificationNetworkService {
30+
31+
private final NetworkStoreService networkStoreService;
32+
private final EquipmentInfosService equipmentInfosService;
33+
private final ModificationApplicationInfosService applicationInfosService;
34+
35+
@Value("${impacts.collection-threshold:50}")
36+
private Integer collectionThreshold;
37+
38+
public ModificationNetworkService(NetworkStoreService networkStoreService, EquipmentInfosService equipmentInfosService, ModificationApplicationInfosService applicationInfosService) {
39+
this.networkStoreService = networkStoreService;
40+
this.equipmentInfosService = equipmentInfosService;
41+
this.applicationInfosService = applicationInfosService;
42+
}
43+
44+
public ModificationNetwork getNetwork(UUID networkUuid, PreloadingStrategy preloadingStrategy) {
45+
Network network;
46+
try {
47+
network = networkStoreService.getNetwork(networkUuid, preloadingStrategy);
48+
} catch (PowsyblException e) {
49+
throw new NetworkModificationException(NETWORK_NOT_FOUND, networkUuid.toString());
50+
}
51+
network.addListener(new NetworkVariantsListener(networkUuid, equipmentInfosService));
52+
NetworkStoreListener listener = NetworkStoreListener.create(
53+
network,
54+
networkUuid,
55+
networkStoreService,
56+
equipmentInfosService,
57+
applicationInfosService,
58+
collectionThreshold
59+
);
60+
return new ModificationNetwork(networkUuid, network, listener);
61+
}
62+
}

0 commit comments

Comments
 (0)