Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource refactoring #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@
import com.powsybl.network.store.client.RestClient;
import com.powsybl.network.store.client.RestClientImpl;
import com.powsybl.network.store.iidm.impl.ConfiguredBusImpl;
import com.powsybl.network.store.iidm.impl.GeneratorImpl;
import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl;
import com.powsybl.network.store.iidm.impl.NetworkImpl;
import com.powsybl.network.store.iidm.impl.extensions.CgmesSshMetadataImpl;
import com.powsybl.network.store.iidm.impl.extensions.CgmesSvMetadataImpl;
import com.powsybl.network.store.iidm.impl.extensions.CimCharacteristicsImpl;
import com.powsybl.network.store.iidm.impl.extensions.*;
import com.powsybl.network.store.model.BaseVoltageSourceAttribute;
import com.powsybl.network.store.model.CgmesSshMetadataAttributes;
import com.powsybl.network.store.model.CgmesSvMetadataAttributes;
Expand All @@ -50,8 +45,8 @@
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextHierarchy;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.*;
Expand Down Expand Up @@ -1659,8 +1654,7 @@ public void cgmesExtensionsTest() {
.cgmesTopologyKind(CgmesTopologyKind.BUS_BRANCH)
.build();

((NetworkImpl) readNetwork).getResource().getAttributes().setCimCharacteristics(cimCharacteristicsAttributes);
((NetworkImpl) readNetwork).updateResource();
((NetworkImpl) readNetwork).updateResource(res -> res.getAttributes().setCimCharacteristics(cimCharacteristicsAttributes));

service.flush(readNetwork);
}
Expand Down Expand Up @@ -1688,25 +1682,22 @@ public void cgmesExtensionsTest() {
assertEquals("modelingAuthoritySetSsh", cgmesSshMetadata.getModelingAuthoritySet());
assertEquals(0, cgmesSshMetadata.getDependencies().size());

cgmesSvMetadata = new CgmesSvMetadataImpl((NetworkImpl) readNetwork,
"Description2",
7,
new ArrayList<>(),
"modelingAuthoritySet2");

cgmesSshMetadata = new CgmesSshMetadataImpl((NetworkImpl) readNetwork,
"DescriptionSsh2",
8,
new ArrayList<>(),
"modelingAuthoritySetSsh2");

cimCharacteristics = new CimCharacteristicsImpl((NetworkImpl) readNetwork,
CgmesTopologyKind.NODE_BREAKER,
6);

readNetwork.addExtension(CgmesSvMetadata.class, cgmesSvMetadata);
readNetwork.addExtension(CgmesSshMetadata.class, cgmesSshMetadata);
readNetwork.addExtension(CimCharacteristics.class, cimCharacteristics);
readNetwork.newExtension(CgmesSvMetadataAdder.class)
.setDescription("Description2")
.setSvVersion(7)
.addDependency("dep2")
.setModelingAuthoritySet("modelingAuthoritySet2")
.add();
readNetwork.newExtension(CgmesSshMetadataAdder.class)
.setDescription("DescriptionSsh2")
.setSshVersion(8)
.addDependency("dep2")
.setModelingAuthoritySet("modelingAuthoritySetSsh2")
.add();
readNetwork.newExtension(CimCharacteristicsAdder.class)
.setTopologyKind(CgmesTopologyKind.NODE_BREAKER)
.setCimVersion(6)
.add();
service.flush(readNetwork);
}

Expand All @@ -1727,11 +1718,11 @@ public void cgmesExtensionsTest() {
assertEquals("Description2", cgmesSvMetadata.getDescription());
assertEquals(7, cgmesSvMetadata.getSvVersion());
assertEquals("modelingAuthoritySet2", cgmesSvMetadata.getModelingAuthoritySet());
assertEquals(0, cgmesSvMetadata.getDependencies().size());
assertEquals(1, cgmesSvMetadata.getDependencies().size());
assertEquals("DescriptionSsh2", cgmesSshMetadata.getDescription());
assertEquals(8, cgmesSshMetadata.getSshVersion());
assertEquals("modelingAuthoritySetSsh2", cgmesSshMetadata.getModelingAuthoritySet());
assertEquals(0, cgmesSshMetadata.getDependencies().size());
assertEquals(1, cgmesSshMetadata.getDependencies().size());
}
}

Expand Down Expand Up @@ -3272,7 +3263,10 @@ public void testActivePowerControlExtension() {
try (NetworkStoreService service = createNetworkStoreService()) {
Network network = EurostagTutorialExample1Factory.create(service.getNetworkFactory());
Generator gen = network.getGenerator("GEN");
gen.addExtension(ActivePowerControl.class, new ActivePowerControlImpl<>(gen, true, 6.3f));
gen.newExtension(ActivePowerControlAdder.class)
.withParticipate(true)
.withDroop(6.3f)
.add();
service.flush(network);
}

Expand All @@ -3292,7 +3286,13 @@ public void testGeneratorStartup() {
try (NetworkStoreService service = createNetworkStoreService()) {
Network network = EurostagTutorialExample1Factory.create(service.getNetworkFactory());
Generator gen = network.getGenerator("GEN");
gen.addExtension(GeneratorStartup.class, new GeneratorStartupImpl((GeneratorImpl) gen, 1.0, 2.0, 3.0, 4.0, 5.0));
gen.newExtension(GeneratorStartupAdder.class)
.withPlannedActivePowerSetpoint(1.0)
.withStartupCost(2.0)
.withMarginalCost(3.0)
.withPlannedOutageRate(4.0)
.withForcedOutageRate(5.0)
.add();
service.flush(network);
}

Expand Down Expand Up @@ -4294,7 +4294,10 @@ public void batteryActivePowerControlTest() {

Battery battery = readNetwork.getBattery("battery");

battery.addExtension(ActivePowerControl.class, new ActivePowerControlImpl<>(battery, false, 1.0f));
battery.newExtension(ActivePowerControlAdder.class)
.withParticipate(false)
.withDroop(1.0f)
.add();
ActivePowerControl activePowerControl = battery.getExtension(ActivePowerControl.class);
assertFalse(activePowerControl.isParticipate());
assertEquals(1.0f, activePowerControl.getDroop(), 0.01);
Expand Down Expand Up @@ -4330,7 +4333,7 @@ public void lccActivePowerControlTest() {

LccConverterStation lccConverterStation = readNetwork.getLccConverterStation("LCC2");

assertThrows(UnsupportedOperationException.class, () -> lccConverterStation.addExtension(ActivePowerControl.class, new ActivePowerControlImpl<>(lccConverterStation, false, 1.0f)))
assertThrows(UnsupportedOperationException.class, () -> lccConverterStation.newExtension(ActivePowerControlAdder.class).withParticipate(false).withDroop(1.0f).add())
.getMessage().contains("Cannot set ActivePowerControl");
assertNull(lccConverterStation.getExtension(ActivePowerControl.class));
}
Expand All @@ -4355,7 +4358,7 @@ public void loadActivePowerControlTest() {

Load load = readNetwork.getLoad("load1");

assertThrows(UnsupportedOperationException.class, () -> load.addExtension(ActivePowerControl.class, new ActivePowerControlImpl<>(load, false, 1.0f)))
assertThrows(UnsupportedOperationException.class, () -> load.newExtension(ActivePowerControlAdder.class).withParticipate(false).withDroop(1.0f).add())
.getMessage().contains("Cannot set ActivePowerControl");
assertNull(load.getExtension(ActivePowerControl.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.ConnectablePosition;
import com.powsybl.network.store.model.*;
import org.joda.time.DateTime;
import org.junit.Test;
Expand Down Expand Up @@ -336,8 +337,8 @@ public void test() throws Exception {
.properties(new HashMap<>(Map.of("property1", "value1", "property2", "value2")))
.aliasesWithoutType(new HashSet<>(Set.of("alias1")))
.aliasByType(new HashMap<>(Map.of("aliasInt", "valueAliasInt", "aliasDouble", "valueAliasDouble")))
.position1(ConnectablePositionAttributes.builder().label("labPosition1").order(1).direction(ConnectableDirection.BOTTOM).build())
.position2(ConnectablePositionAttributes.builder().label("labPosition2").order(2).direction(ConnectableDirection.TOP).build())
.position1(ConnectablePositionAttributes.builder().label("labPosition1").order(1).direction(ConnectablePosition.Direction.BOTTOM).build())
.position2(ConnectablePositionAttributes.builder().label("labPosition2").order(2).direction(ConnectablePosition.Direction.TOP).build())
.mergedXnode(MergedXnodeAttributes.builder().rdp(50.).build())
.currentLimits1(LimitsAttributes.builder().permanentLimit(20.).build())
.build())
Expand Down Expand Up @@ -461,8 +462,8 @@ public void test() throws Exception {
.properties(new HashMap<>(Map.of("property12", "value12", "property22", "value22")))
.aliasesWithoutType(new HashSet<>(Set.of("alias12")))
.aliasByType(new HashMap<>(Map.of("aliasInt2", "valueAliasInt2", "aliasDouble2", "valueAliasDouble2")))
.position1(ConnectablePositionAttributes.builder().label("labPosition12").order(4).direction(ConnectableDirection.BOTTOM).build())
.position2(ConnectablePositionAttributes.builder().label("labPosition22").order(9).direction(ConnectableDirection.TOP).build())
.position1(ConnectablePositionAttributes.builder().label("labPosition12").order(4).direction(ConnectablePosition.Direction.BOTTOM).build())
.position2(ConnectablePositionAttributes.builder().label("labPosition22").order(9).direction(ConnectablePosition.Direction.TOP).build())
.mergedXnode(MergedXnodeAttributes.builder().rdp(80.).build())
.currentLimits1(LimitsAttributes.builder().permanentLimit(30.).build())
.build())
Expand Down