Skip to content

Commit

Permalink
Create action to change shunt compensator position
Browse files Browse the repository at this point in the history
Signed-off-by: VEDELAGO MIORA <miora.ralambotiana@rte-france.com>
  • Loading branch information
miovd committed Mar 10, 2023
1 parent f067e75 commit f45671d
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.security.action;

/**
* @author Miora Vedelago <miora.ralambotiana at rte-france.com>
*/
public class ShuntCompensatorPositionAction extends AbstractAction {

public static final String NAME = "SHUNT_COMPENSATOR_POSITION";

private final String shuntCompensatorId;
private final int sectionCount;

ShuntCompensatorPositionAction(String id, String shuntCompensatorId, int sectionCount) {
super(id);
this.shuntCompensatorId = shuntCompensatorId;
this.sectionCount = sectionCount;
}

@Override
public String getType() {
return NAME;
}

public String getShuntCompensatorId() {
return shuntCompensatorId;
}

public int getSectionCount() {
return sectionCount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.security.action;

/**
* @author Miora Vedelago <miora.ralambotiana at rte-france.com>
*/
public class ShuntCompensatorPositionActionBuilder {

private String id;
private String shuntCompensatorId;
private Integer sectionCount = null;

public ShuntCompensatorPositionAction build() {
if (sectionCount == null) {
throw new IllegalArgumentException("sectionCount in undefined");
}
if (sectionCount < 0) {
throw new IllegalArgumentException("sectionCount should be position for a shunt compensator");
}
return new ShuntCompensatorPositionAction(id, shuntCompensatorId, sectionCount);
}

public ShuntCompensatorPositionActionBuilder withId(String id) {
this.id = id;
return this;
}

public ShuntCompensatorPositionActionBuilder withShuntCompensatorId(String shuntCompensatorId) {
this.shuntCompensatorId = shuntCompensatorId;
return this;
}

public ShuntCompensatorPositionActionBuilder withSectionCount(int sectionCount) {
this.sectionCount = sectionCount;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ private void configureActionsSerialization() {
new GeneratorActionSerializer(), new GeneratorActionDeserializer());
registerActionType(LoadAction.class, LoadAction.NAME,
new LoadActionSerializer(), new LoadActionDeserializer());
registerActionType(ShuntCompensatorPositionAction.class, ShuntCompensatorPositionAction.NAME,
new ShuntCompensatorPositionActionSerializer(), new ShuntCompensatorPositionActionDeserializer());
}

private <T> void registerActionType(Class<T> actionClass, String typeName, JsonSerializer<T> serializer, JsonDeserializer<T> deserializer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.security.json.action;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.powsybl.commons.json.JsonUtil;
import com.powsybl.security.action.ShuntCompensatorPositionAction;
import com.powsybl.security.action.ShuntCompensatorPositionActionBuilder;

import java.io.IOException;

/**
* @author Miora Vedelago <miora.ralambotiana at rte-france.com>
*/
public class ShuntCompensatorPositionActionDeserializer extends StdDeserializer<ShuntCompensatorPositionAction> {

public ShuntCompensatorPositionActionDeserializer() {
super(ShuntCompensatorPositionAction.class);
}

private static class ParsingContext {
String id;
String shuntCompensatorId;
Integer sectionCount = null;
}

@Override
public ShuntCompensatorPositionAction deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
ParsingContext context = new ParsingContext();
JsonUtil.parsePolymorphicObject(jsonParser, name -> {
switch (name) {
case "type":
if (!ShuntCompensatorPositionAction.NAME.equals(jsonParser.nextTextValue())) {
throw JsonMappingException.from(jsonParser, "Expected type " + ShuntCompensatorPositionAction.NAME);
}
return true;
case "id":
context.id = jsonParser.nextTextValue();
return true;
case "shuntCompensatorId":
context.shuntCompensatorId = jsonParser.nextTextValue();
return true;
case "sectionCount":
jsonParser.nextToken();
context.sectionCount = jsonParser.getValueAsInt();
return true;
default:
return false;
}
});
return new ShuntCompensatorPositionActionBuilder()
.withId(context.id)
.withShuntCompensatorId(context.shuntCompensatorId)
.withSectionCount(context.sectionCount)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.security.json.action;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.powsybl.security.action.ShuntCompensatorPositionAction;

import java.io.IOException;

/**
* @author Miora Vedelago <miora.ralambotiana at rte-france.com>
*/
public class ShuntCompensatorPositionActionSerializer extends StdSerializer<ShuntCompensatorPositionAction> {

public ShuntCompensatorPositionActionSerializer() {
super(ShuntCompensatorPositionAction.class);
}

@Override
public void serialize(ShuntCompensatorPositionAction action, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("type", action.getType());
jsonGenerator.writeStringField("id", action.getId());
jsonGenerator.writeStringField("shuntCompensatorId", action.getShuntCompensatorId());
jsonGenerator.writeNumberField("sectionCount", action.getSectionCount());
jsonGenerator.writeEndObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void actionRoundTrip() throws IOException {
PhaseTapChanger.RegulationMode.ACTIVE_POWER_CONTROL, 15.0));
actions.add(RatioTapChangerRegulationAction.activateRegulationAndChangeTargetV("id20", "transformerId5", 90.0));
actions.add(RatioTapChangerRegulationAction.deactivateRegulation("id21", "transformerId5", ThreeWindingsTransformer.Side.THREE));
actions.add(new ShuntCompensatorPositionActionBuilder().withId("id22").withShuntCompensatorId("shuntId1").withSectionCount(5).build());
ActionList actionList = new ActionList(actions);
roundTripTest(actionList, ActionList::writeJsonFile, ActionList::readJsonFile, "/ActionFileTest.json");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,10 @@
"transformerId" : "transformerId5",
"regulating" : false,
"side" : "THREE"
}, {
"type" : "SHUNT_COMPENSATOR_POSITION",
"id" : "id22",
"shuntCompensatorId" : "shuntId1",
"sectionCount" : 5
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,10 @@
"transformerId" : "transformerId5",
"regulating" : false,
"side" : "THREE"
}, {
"type" : "SHUNT_COMPENSATOR_POSITION",
"id" : "id22",
"shuntCompensatorId" : "shuntId1",
"sectionCount" : 5
} ]
}

0 comments on commit f45671d

Please sign in to comment.