Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -19,13 +19,16 @@
import org.gridsuite.modification.dto.tabular.LimitSetsTabularModificationInfos;
import org.gridsuite.modification.dto.tabular.TabularCreationInfos;
import org.gridsuite.modification.dto.tabular.TabularModificationInfos;
import org.gridsuite.modification.error.NetworkModificationException;
import org.gridsuite.modification.modifications.AbstractModification;

import java.time.Instant;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;

import static org.gridsuite.modification.error.NetworkModificationExceptionType.MISSING_ROOT_NETWORK_APPLICABILITY;

/**
* @author Slimane Amar <slimane.amar at rte-france.com>
*/
Expand Down Expand Up @@ -161,16 +164,23 @@ public Map<String, String> getMapMessageValues() {

/**
* A modification is activated on a root network when it is not stashed, when it is globally activated and when
* its applicability for that root network tag is not explicitly set to false. A tag without any entry is
* applicable, and a null tag matches any root network.
* its applicability for that root network tag is true. A null tag matches any root network.
*
* @throws NetworkModificationException when the modification holds no applicability for that tag
*/
public boolean isActivatedOn(String rootNetworkTag) {
if (Boolean.TRUE.equals(stashed) || !Boolean.TRUE.equals(activated)) {
return false;
}
return rootNetworkTag == null
|| applicabilityByRootNetworkTag == null
|| !Boolean.FALSE.equals(applicabilityByRootNetworkTag.get(rootNetworkTag));
if (rootNetworkTag == null) {
return true;
}
Boolean applicable = applicabilityByRootNetworkTag == null ? null : applicabilityByRootNetworkTag.get(rootNetworkTag);
if (applicable == null) {
throw new NetworkModificationException(MISSING_ROOT_NETWORK_APPLICABILITY,
String.format("modification %s, root network tag %s", uuid, rootNetworkTag));
}
return applicable;
}

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public enum NetworkModificationExceptionType {
UNSUPPORTED_HYBRID_HVDC("The hybrid HVDC line is not supported"),
MODIFY_VOLTAGE_LEVEL_TOPOLOGY_ERROR("An error occurred while modifying the voltage level topology"),
CREATE_VOLTAGE_LEVEL_TOPOLOGY_ERROR("An error occurred while creating the voltage level topology"),
MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_ERROR("An error occurred while moving the voltage level feeder bays");
MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_ERROR("An error occurred while moving the voltage level feeder bays"),
MISSING_ROOT_NETWORK_APPLICABILITY("The modification has no applicability for the root network");

private final String message;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.powsybl.commons.report.ReportNode;
import org.gridsuite.modification.context.ModificationContext;
import org.gridsuite.modification.error.NetworkModificationException;
import org.junit.jupiter.api.Test;

import java.util.Collections;
Expand Down Expand Up @@ -116,24 +117,35 @@ void testActivatedWhenNoRootNetworkTagGiven() {
}

@Test
void testActivatedWhenNoApplicabilityDefined() {
assertTrue(modificationInfos(true, null).isActivatedOn(TAG),
"A modification without any applicability is activated on every root network");
void testThrowsWhenNoApplicabilityDefined() {
ModificationInfos modificationInfos = modificationInfos(true, null);
assertThrows(NetworkModificationException.class, () -> modificationInfos.isActivatedOn(TAG),
"A modification without any applicability is associated with no root network");
assertTrue(modificationInfos.isActivatedOn(null),
"Without a root network context, no applicability is needed");
}

@Test
void testActivatedWhenTagHasNoEntry() {
assertTrue(modificationInfos(true, Map.of()).isActivatedOn(TAG),
"A modification without any applicability entry for a tag is activated on it");
assertTrue(modificationInfos(true, Map.of(OTHER_TAG, false)).isActivatedOn(TAG),
"An entry deactivating another tag leaves this one applicable");
void testThrowsWhenTagHasNoEntry() {
ModificationInfos withoutEntry = modificationInfos(true, Map.of());
assertThrows(NetworkModificationException.class, () -> withoutEntry.isActivatedOn(TAG),
"A modification without any applicability entry for a tag is not associated with it");
ModificationInfos withOtherEntry = modificationInfos(true, Map.of(OTHER_TAG, false));
assertThrows(NetworkModificationException.class, () -> withOtherEntry.isActivatedOn(TAG),
"An entry for another tag says nothing about this one");
}

@Test
void testActivatedWhenTagEntryIsNull() {
// singletonMap, not Map.of, which rejects a null value
assertTrue(modificationInfos(true, Collections.singletonMap(TAG, null)).isActivatedOn(TAG),
"A tag mapped to no value is applicable: only an explicit false deactivates it");
void testThrowsWhenTagEntryIsNull() {
ModificationInfos modificationInfos = modificationInfos(true, Collections.singletonMap(TAG, null));
assertThrows(NetworkModificationException.class, () -> modificationInfos.isActivatedOn(TAG),
"A tag mapped to no value is not an applicability");
}

@Test
void testNoApplicabilityNeededWhenNotActivated() {
assertFalse(modificationInfos(false, Map.of()).isActivatedOn(TAG),
"A deactivated modification is not applied, whether it is associated with the root network or not");
}

@Test
Expand Down
Loading