-
Notifications
You must be signed in to change notification settings - Fork 43
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
Create action to change shunt compensator position #2497
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
34154c9
Create action to change shunt compensator position
miovd 6ed1ece
Typo
miovd 684f0d4
Delete blank spaces in JSON test files
miovd 1450de8
Merge branch 'main' into shunt_position_action
flo-dup 7eff90f
Revert ActionFileTestV1.0.json
miovd 7b8144b
Delete useless JacksonException in method signature (code smells)
miovd dec294d
Merge branch 'main' into shunt_position_action
miovd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...nalysis-api/src/main/java/com/powsybl/security/action/ShuntCompensatorPositionAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...-api/src/main/java/com/powsybl/security/action/ShuntCompensatorPositionActionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
miovd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new IllegalArgumentException("sectionCount should be positive 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...ain/java/com/powsybl/security/json/action/ShuntCompensatorPositionActionDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
miovd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
.../main/java/com/powsybl/security/json/action/ShuntCompensatorPositionActionSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version" : "1.0", | ||
miovd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"version" : "1.1", | ||
"actions" : [ { | ||
"type" : "SWITCH", | ||
"id" : "id1", | ||
|
@@ -30,27 +30,27 @@ | |
"type" : "PHASE_TAP_CHANGER_TAP_POSITION", | ||
"id" : "id5", | ||
"transformerId" : "transformerId1", | ||
"value" : 5, | ||
"tapPosition" : 5, | ||
"relativeValue" : true, | ||
"side" : "TWO" | ||
}, { | ||
"type" : "PHASE_TAP_CHANGER_TAP_POSITION", | ||
"id" : "id6", | ||
"transformerId" : "transformerId2", | ||
"value" : 12, | ||
"tapPosition" : 12, | ||
"relativeValue" : false | ||
}, { | ||
"type" : "PHASE_TAP_CHANGER_TAP_POSITION", | ||
"id" : "id7", | ||
"transformerId" : "transformerId3", | ||
"value" : -5, | ||
"tapPosition" : -5, | ||
"relativeValue" : true, | ||
"side" : "ONE" | ||
}, { | ||
"type" : "PHASE_TAP_CHANGER_TAP_POSITION", | ||
"id" : "id8", | ||
"transformerId" : "transformerId3", | ||
"value" : 2, | ||
"tapPosition" : 2, | ||
"relativeValue" : false, | ||
"side" : "THREE" | ||
}, { | ||
|
@@ -87,14 +87,14 @@ | |
"type" : "RATIO_TAP_CHANGER_TAP_POSITION", | ||
"id" : "id14", | ||
"transformerId" : "transformerId4", | ||
"value" : 2, | ||
"tapPosition" : 2, | ||
"relativeValue" : false, | ||
"side" : "THREE" | ||
}, { | ||
"type" : "RATIO_TAP_CHANGER_TAP_POSITION", | ||
"id" : "id15", | ||
"transformerId" : "transformerId5", | ||
"value" : 1, | ||
"tapPosition" : 1, | ||
"relativeValue" : true | ||
}, { | ||
"type" : "RATIO_TAP_CHANGER_REGULATION", | ||
|
@@ -162,5 +162,10 @@ | |
"acEmulationEnabled" : false, | ||
"activePowerSetpoint" : 12.0, | ||
"relativeValue" : true | ||
}, { | ||
"type" : "SHUNT_COMPENSATOR_POSITION", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed, it's a bit strange to have new type of actions in v1.0 (or in v1.1), but it seems that this kind of forward-compatibility is the way the versions are dealt with here. |
||
"id" : "id22", | ||
"shuntCompensatorId" : "shuntId1", | ||
"sectionCount" : 5 | ||
} ] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Position or section?