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

Add network events to IIDM API #3203

Merged
merged 11 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -28,11 +28,6 @@ public void afterRemoval(String identifiable) {
// empty default implementation
}

@Override
public void onUpdate(Identifiable<?> identifiable, String attribute, Object oldValue, Object newValue) {
// empty default implementation
}

@Override
public void onUpdate(Identifiable<?> identifiable, String attribute, String variantId, Object oldValue, Object newValue) {
// empty default implementation
Expand All @@ -44,7 +39,7 @@ public void onExtensionCreation(Extension<?> extension) {
}

@Override
public void onExtensionUpdate(Extension<?> extension, String attribute, Object oldValue, Object newValue) {
public void onExtensionUpdate(Extension<?> extension, String attribute, String variantId, Object oldValue, Object newValue) {
// empty default implementation
}

Expand All @@ -57,4 +52,34 @@ public void onExtensionBeforeRemoval(Extension<?> extension) {
public void onExtensionAfterRemoval(Identifiable<?> identifiable, String extensionName) {
// empty default implementation
}

@Override
public void onPropertyAdded(Identifiable<?> identifiable, String attribute, Object newValue) {
// empty default implementation
}

@Override
public void onPropertyReplaced(Identifiable<?> identifiable, String attribute, Object oldValue, Object newValue) {
// empty default implementation
}

@Override
public void onPropertyRemoved(Identifiable<?> identifiable, String attribute, Object oldValue) {
// empty default implementation
}

@Override
public void onVariantCreated(String sourceVariantId, String targetVariantId) {
// empty default implementation
}

@Override
public void onVariantOverwritten(String sourceVariantId, String targetVariantId) {
// empty default implementation
}

@Override
public void onVariantRemoved(String variantId) {
// empty default implementation
}
}
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 attribute, Object newValue) {
events.add(new PropertyUpdateNetworkEvent(identifiable.getId(), attribute, PropertyUpdateNetworkEvent.PropertyUpdateType.ADDED, null, newValue));
}

@Override
public void onPropertyReplaced(Identifiable<?> identifiable, String attribute, Object oldValue, Object newValue) {
flo-dup marked this conversation as resolved.
Show resolved Hide resolved
events.add(new PropertyUpdateNetworkEvent(identifiable.getId(), attribute, PropertyUpdateNetworkEvent.PropertyUpdateType.REPLACED, oldValue, newValue));
}

@Override
public void onPropertyRemoved(Identifiable<?> identifiable, String attribute, Object oldValue) {
events.add(new PropertyUpdateNetworkEvent(identifiable.getId(), attribute, PropertyUpdateNetworkEvent.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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public interface NetworkListener {

void afterRemoval(String id);

void onUpdate(Identifiable<?> identifiable, String attribute, Object oldValue, Object newValue);

void onUpdate(Identifiable<?> identifiable, String attribute, String variantId, Object oldValue, Object newValue);

void onExtensionCreation(Extension<?> extension);
Expand All @@ -30,29 +28,17 @@ public interface NetworkListener {

void onExtensionBeforeRemoval(Extension<?> extension);

void onExtensionUpdate(Extension<?> extendable, String attribute, Object oldValue, Object newValue);
void onExtensionUpdate(Extension<?> extendable, String attribute, String variantId, Object oldValue, Object newValue);

default void onElementAdded(Identifiable<?> identifiable, String attribute, Object newValue) {
// empty default implementation
}
void onPropertyAdded(Identifiable<?> identifiable, String attribute, Object newValue);

default void onElementReplaced(Identifiable<?> identifiable, String attribute, Object oldValue, Object newValue) {
// empty default implementation
}
void onPropertyReplaced(Identifiable<?> identifiable, String attribute, Object oldValue, Object newValue);

default void onElementRemoved(Identifiable<?> identifiable, String attribute, Object oldValue) {
// empty default implementation
}
void onPropertyRemoved(Identifiable<?> identifiable, String attribute, Object oldValue);

default void onVariantCreated(String sourceVariantId, String targetVariantId) {
// empty default implementation
}
void onVariantCreated(String sourceVariantId, String targetVariantId);

default void onVariantOverwritten(String sourceVariantId, String targetVariantId) {
// empty default implementation
}
void onVariantOverwritten(String sourceVariantId, String targetVariantId);

default void onVariantRemoved(String variantId) {
// empty default implementation
}
void onVariantRemoved(String variantId);
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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,
PROPERTY_UPDATE,
EXTENSION_CREATION,
EXTENSION_REMOVAL,
EXTENSION_UPDATE,
VARIANT,
}

Type getType();
}
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 PropertyUpdateNetworkEvent(String id, String attribute, PropertyUpdateType updateType, Object oldValue, Object newValue) implements NetworkEvent {
flo-dup marked this conversation as resolved.
Show resolved Hide resolved

public enum PropertyUpdateType {
ADDED,
REMOVED,
REPLACED;
}

public PropertyUpdateNetworkEvent {
Objects.requireNonNull(id);
Objects.requireNonNull(attribute);
Objects.requireNonNull(updateType);
}

@Override
public Type getType() {
return Type.PROPERTY_UPDATE;
}
}
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;
}
}
Loading