-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add network events to IIDM API (#3203)
* Add network events to IIDM API * Add unit tests * Clean all deprecated methods and remame element to property Signed-off-by: Geoffroy Jamgotchian <[email protected]>
- Loading branch information
Showing
34 changed files
with
625 additions
and
223 deletions.
There are no files selected for viewing
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
100 changes: 100 additions & 0 deletions
100
iidm/iidm-api/src/main/java/com/powsybl/iidm/network/NetworkEventRecorder.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,100 @@ | ||
/** | ||
* Copyright (c) 2024, 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.iidm.network; | ||
|
||
import com.powsybl.commons.extensions.Extension; | ||
import com.powsybl.iidm.network.events.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>} | ||
*/ | ||
public class NetworkEventRecorder implements NetworkListener { | ||
|
||
private final List<NetworkEvent> events = new ArrayList<>(); | ||
|
||
public List<NetworkEvent> getEvents() { | ||
return events; | ||
} | ||
|
||
public void reset() { | ||
events.clear(); | ||
} | ||
|
||
@Override | ||
public void onCreation(Identifiable<?> identifiable) { | ||
events.add(new CreationNetworkEvent(identifiable.getId())); | ||
} | ||
|
||
@Override | ||
public void beforeRemoval(Identifiable<?> identifiable) { | ||
events.add(new RemovalNetworkEvent(identifiable.getId(), false)); | ||
} | ||
|
||
@Override | ||
public void afterRemoval(String id) { | ||
events.add(new RemovalNetworkEvent(id, true)); | ||
} | ||
|
||
@Override | ||
public void onUpdate(Identifiable<?> identifiable, String attribute, String variantId, Object oldValue, Object newValue) { | ||
events.add(new UpdateNetworkEvent(identifiable.getId(), attribute, variantId, oldValue, newValue)); | ||
} | ||
|
||
@Override | ||
public void onExtensionCreation(Extension<?> extension) { | ||
events.add(new ExtensionCreationNetworkEvent(((Identifiable<?>) extension.getExtendable()).getId(), extension.getName())); | ||
} | ||
|
||
@Override | ||
public void onExtensionAfterRemoval(Identifiable<?> identifiable, String extensionName) { | ||
events.add(new ExtensionRemovalNetworkEvent(identifiable.getId(), extensionName, true)); | ||
} | ||
|
||
@Override | ||
public void onExtensionBeforeRemoval(Extension<?> extension) { | ||
events.add(new ExtensionRemovalNetworkEvent(((Identifiable<?>) extension.getExtendable()).getId(), extension.getName(), false)); | ||
} | ||
|
||
@Override | ||
public void onExtensionUpdate(Extension<?> extension, String attribute, String variantId, Object oldValue, Object newValue) { | ||
events.add(new ExtensionUpdateNetworkEvent(((Identifiable<?>) extension.getExtendable()).getId(), extension.getName(), attribute, variantId, oldValue, newValue)); | ||
} | ||
|
||
@Override | ||
public void onPropertyAdded(Identifiable<?> identifiable, String key, Object newValue) { | ||
events.add(new PropertiesUpdateNetworkEvent(identifiable.getId(), key, PropertiesUpdateNetworkEvent.PropertyUpdateType.ADDED, null, newValue)); | ||
} | ||
|
||
@Override | ||
public void onPropertyReplaced(Identifiable<?> identifiable, String key, Object oldValue, Object newValue) { | ||
events.add(new PropertiesUpdateNetworkEvent(identifiable.getId(), key, PropertiesUpdateNetworkEvent.PropertyUpdateType.REPLACED, oldValue, newValue)); | ||
} | ||
|
||
@Override | ||
public void onPropertyRemoved(Identifiable<?> identifiable, String key, Object oldValue) { | ||
events.add(new PropertiesUpdateNetworkEvent(identifiable.getId(), key, PropertiesUpdateNetworkEvent.PropertyUpdateType.REMOVED, oldValue, null)); | ||
} | ||
|
||
@Override | ||
public void onVariantCreated(String sourceVariantId, String targetVariantId) { | ||
events.add(new VariantNetworkEvent(sourceVariantId, targetVariantId, VariantNetworkEvent.VariantEventType.CREATED)); | ||
} | ||
|
||
@Override | ||
public void onVariantOverwritten(String sourceVariantId, String targetVariantId) { | ||
events.add(new VariantNetworkEvent(sourceVariantId, targetVariantId, VariantNetworkEvent.VariantEventType.OVERWRITTEN)); | ||
} | ||
|
||
@Override | ||
public void onVariantRemoved(String variantId) { | ||
events.add(new VariantNetworkEvent(variantId, null, VariantNetworkEvent.VariantEventType.REMOVED)); | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
iidm/iidm-api/src/main/java/com/powsybl/iidm/network/events/CreationNetworkEvent.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,24 @@ | ||
/** | ||
* Copyright (c) 2024, 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.iidm.network.events; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>} | ||
*/ | ||
public record CreationNetworkEvent(String id) implements NetworkEvent { | ||
public CreationNetworkEvent { | ||
Objects.requireNonNull(id); | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return Type.CREATION; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...iidm-api/src/main/java/com/powsybl/iidm/network/events/ExtensionCreationNetworkEvent.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,25 @@ | ||
/** | ||
* Copyright (c) 2024, 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.iidm.network.events; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>} | ||
*/ | ||
public record ExtensionCreationNetworkEvent(String id, String extensionName) implements NetworkEvent { | ||
public ExtensionCreationNetworkEvent { | ||
Objects.requireNonNull(id); | ||
Objects.requireNonNull(extensionName); | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return Type.EXTENSION_CREATION; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
.../iidm-api/src/main/java/com/powsybl/iidm/network/events/ExtensionRemovalNetworkEvent.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,25 @@ | ||
/** | ||
* Copyright (c) 2024, 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.iidm.network.events; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>} | ||
*/ | ||
public record ExtensionRemovalNetworkEvent(String id, String extensionName, boolean after) implements NetworkEvent { | ||
public ExtensionRemovalNetworkEvent { | ||
Objects.requireNonNull(id); | ||
Objects.requireNonNull(extensionName); | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return Type.EXTENSION_REMOVAL; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
iidm/iidm-api/src/main/java/com/powsybl/iidm/network/events/ExtensionUpdateNetworkEvent.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,26 @@ | ||
/** | ||
* Copyright (c) 2024, 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.iidm.network.events; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>} | ||
*/ | ||
public record ExtensionUpdateNetworkEvent(String id, String extensionName, String attribute, String variantId, Object oldValue, Object newValue) implements NetworkEvent { | ||
public ExtensionUpdateNetworkEvent { | ||
Objects.requireNonNull(id); | ||
Objects.requireNonNull(extensionName); | ||
Objects.requireNonNull(attribute); | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return Type.EXTENSION_UPDATE; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
iidm/iidm-api/src/main/java/com/powsybl/iidm/network/events/NetworkEvent.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,26 @@ | ||
/** | ||
* Copyright (c) 2024, 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.iidm.network.events; | ||
|
||
/** | ||
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>} | ||
*/ | ||
public interface NetworkEvent { | ||
enum Type { | ||
CREATION, | ||
REMOVAL, | ||
UPDATE, | ||
PROPERTIES_UPDATE, | ||
EXTENSION_CREATION, | ||
EXTENSION_REMOVAL, | ||
EXTENSION_UPDATE, | ||
VARIANT, | ||
} | ||
|
||
Type getType(); | ||
} |
33 changes: 33 additions & 0 deletions
33
.../iidm-api/src/main/java/com/powsybl/iidm/network/events/PropertiesUpdateNetworkEvent.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,33 @@ | ||
/** | ||
* Copyright (c) 2024, 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.iidm.network.events; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>} | ||
*/ | ||
public record PropertiesUpdateNetworkEvent(String id, String key, PropertyUpdateType updateType, Object oldValue, Object newValue) implements NetworkEvent { | ||
|
||
public enum PropertyUpdateType { | ||
ADDED, | ||
REMOVED, | ||
REPLACED; | ||
} | ||
|
||
public PropertiesUpdateNetworkEvent { | ||
Objects.requireNonNull(id); | ||
Objects.requireNonNull(key); | ||
Objects.requireNonNull(updateType); | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return Type.PROPERTIES_UPDATE; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
iidm/iidm-api/src/main/java/com/powsybl/iidm/network/events/RemovalNetworkEvent.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,24 @@ | ||
/** | ||
* Copyright (c) 2024, 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.iidm.network.events; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>} | ||
*/ | ||
public record RemovalNetworkEvent(String id, boolean after) implements NetworkEvent { | ||
public RemovalNetworkEvent { | ||
Objects.requireNonNull(id); | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return Type.REMOVAL; | ||
} | ||
} |
Oops, something went wrong.