-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create action to change shunt compensator position
Signed-off-by: VEDELAGO MIORA <miora.ralambotiana@rte-france.com>
- Loading branch information
Showing
8 changed files
with
195 additions
and
0 deletions.
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) { | ||
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; | ||
} | ||
} |
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 { | ||
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