diff --git a/data/result-exporter/cne-exporter-commons/src/main/java/com/farao_community/farao/data/cne_exporter_commons/TsoEICode.java b/commons/src/main/java/com/farao_community/farao/commons/TsoEICode.java similarity index 97% rename from data/result-exporter/cne-exporter-commons/src/main/java/com/farao_community/farao/data/cne_exporter_commons/TsoEICode.java rename to commons/src/main/java/com/farao_community/farao/commons/TsoEICode.java index 756f3efcc1..2fb18c9118 100644 --- a/data/result-exporter/cne-exporter-commons/src/main/java/com/farao_community/farao/data/cne_exporter_commons/TsoEICode.java +++ b/commons/src/main/java/com/farao_community/farao/commons/TsoEICode.java @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package com.farao_community.farao.data.cne_exporter_commons; +package com.farao_community.farao.commons; import java.util.Arrays; @@ -80,4 +80,3 @@ public static TsoEICode fromEICode(String eiCode) { return Arrays.stream(TsoEICode.values()).filter(tsoEICode -> tsoEICode.eiCode.equals(eiCode)).findAny().orElseThrow(); } } - diff --git a/data/crac-creation/crac-creator-cim/pom.xml b/data/crac-creation/crac-creator-cim/pom.xml index 73fb9d1cb3..f3b0a2ecbc 100644 --- a/data/crac-creation/crac-creator-cim/pom.xml +++ b/data/crac-creation/crac-creator-cim/pom.xml @@ -43,7 +43,9 @@ org.apache.maven.plugins maven-javadoc-plugin - com.farao_community.farao.data.crac_creation.creator.cim.xsd.*:com.farao_community.farao.data.crac_creation.creator.cim.xsd:eu.entsoe.* + + com.farao_community.farao.data.crac_creation.creator.cim.xsd.*:com.farao_community.farao.data.crac_creation.creator.cim.xsd:eu.entsoe.* + diff --git a/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/contingency/CimContingencyCreator.java b/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/contingency/CimContingencyCreator.java index cdbf588f73..aadd1bee3a 100644 --- a/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/contingency/CimContingencyCreator.java +++ b/data/crac-creation/crac-creator-cim/src/main/java/com/farao_community/farao/data/crac_creation/creator/cim/crac_creator/contingency/CimContingencyCreator.java @@ -18,14 +18,14 @@ import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.TieLine; -import static com.farao_community.farao.data.crac_creation.creator.cim.crac_creator.CimConstants.CONTINGENCY_SERIES_BUSINESS_TYPE; - import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import static com.farao_community.farao.data.crac_creation.creator.cim.crac_creator.CimConstants.CONTINGENCY_SERIES_BUSINESS_TYPE; + /** * @author Godelaine de Montmorillon {@literal } */ @@ -67,8 +67,8 @@ public void createAndAddContingencies() { private void addContingency(ContingencySeries cimContingency) { String createdContingencyId = cimContingency.getMRID(); ContingencyAdder contingencyAdder = crac.newContingency() - .withId(createdContingencyId) - .withName(cimContingency.getName()); + .withId(createdContingencyId) + .withName(cimContingency.getName()); if (cimContingency.getRegisteredResource().isEmpty()) { cimContingencyCreationContexts.add(CimContingencyCreationContext.notImported(createdContingencyId, cimContingency.getName(), ImportStatus.INCOMPLETE_DATA, "No registered resources")); diff --git a/data/crac-creation/crac-creator-csa-profiles/pom.xml b/data/crac-creation/crac-creator-csa-profiles/pom.xml new file mode 100644 index 0000000000..a739e8e4dd --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/pom.xml @@ -0,0 +1,106 @@ + + + + + + farao-crac-creation + com.farao-community.farao + 4.5.0-SNAPSHOT + + 4.0.0 + + farao-crac-creator-csa-profiles + CRAC creator - CSA Profiles + CRAC creator implementation for CRAC specific to CSA profiles + jar + + + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + -Xinheritance + + + + org.jvnet.jaxb2_commons + jaxb2-basics + ${maven.jvnet.jaxb2-basics.version} + + + + + + + + + + ${project.groupId} + farao-crac-creator-api + ${project.version} + + + ${project.groupId} + farao-crac-creation-util + ${project.version} + + + ${project.groupId} + farao-crac-io-api + ${project.version} + + + ${project.groupId} + farao-crac-util + ${project.version} + + + org.eclipse.rdf4j + rdf4j-rio-rdfxml + 4.2.2 + + + + + ${project.groupId} + farao-crac-impl + ${project.version} + runtime + + + com.powsybl + powsybl-triple-store-impl-rdf4j + ${powsybl.core.version} + + + com.powsybl + powsybl-iidm-impl + ${powsybl.core.version} + + + com.powsybl + powsybl-cgmes-conversion + ${powsybl.core.version} + test + + + org.junit.jupiter + junit-jupiter + + + org.mockito + mockito-inline + test + + + + \ No newline at end of file diff --git a/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/CsaProfileCrac.java b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/CsaProfileCrac.java new file mode 100644 index 0000000000..20eca5d3ae --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/CsaProfileCrac.java @@ -0,0 +1,86 @@ +/* + * 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/. + */ + +package com.farao_community.farao.data.crac_creation.creator.csa_profile; + +import com.farao_community.farao.commons.logs.FaraoLoggerProvider; +import com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator.CsaProfileConstants; +import com.farao_community.farao.data.native_crac_api.NativeCrac; +import com.powsybl.triplestore.api.PropertyBags; +import com.powsybl.triplestore.api.QueryCatalog; +import com.powsybl.triplestore.api.TripleStore; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * @author Jean-Pierre Arnould {@literal } + */ +public class CsaProfileCrac implements NativeCrac { + + private final TripleStore tripleStoreCsaProfileCrac; + + private final QueryCatalog queryCatalogCsaProfileCrac; + + public CsaProfileCrac(TripleStore tripleStoreCsaProfileCrac) { + this.tripleStoreCsaProfileCrac = tripleStoreCsaProfileCrac; + this.queryCatalogCsaProfileCrac = new QueryCatalog(CsaProfileConstants.SPARQL_FILE_CSA_PROFILE); + } + + @Override + public String getFormat() { + return "CsaProfileCrac"; + } + + public PropertyBags getContingencies() { + return this.queryTripleStore(Arrays.asList(CsaProfileConstants.REQUEST_ORDINARY_CONTINGENCY, CsaProfileConstants.REQUEST_EXCEPTIONAL_CONTINGENCY, CsaProfileConstants.REQUEST_OUT_OF_RANGE_CONTINGENCY), tripleStoreCsaProfileCrac.contextNames()); + } + + public PropertyBags getContingencyEquipments() { + return this.queryTripleStore(CsaProfileConstants.REQUEST_CONTINGENCY_EQUIPMENT); + } + + private PropertyBags queryTripleStore(String queryKey) { + return this.queryTripleStore(queryKey, new HashSet<>()); + } + + private PropertyBags queryTripleStore(List queryKeys, Set contexts) { + PropertyBags mergedPropertyBags = new PropertyBags(); + for (String queryKey : queryKeys) { + mergedPropertyBags.addAll(queryTripleStore(queryKey, contexts)); + } + return mergedPropertyBags; + } + + /** + * execute query on the whole tripleStore or on each context included in the set + * + * @param queryKey : query name in the sparql file + * @param contexts : list of contexts where the query will be executed (if empty, the query is executed on the whole tripleStore + * @return + */ + private PropertyBags queryTripleStore(String queryKey, Set contexts) { + String query = queryCatalogCsaProfileCrac.get(queryKey); + if (query == null) { + FaraoLoggerProvider.TECHNICAL_LOGS.warn("Query [{}] not found in catalog", queryKey); + return new PropertyBags(); + } + + if (contexts.isEmpty()) { + return tripleStoreCsaProfileCrac.query(query); + } + + PropertyBags multiContextsPropertyBags = new PropertyBags(); + for (String context : contexts) { + String contextQuery = String.format(query, context); + multiContextsPropertyBags.addAll(tripleStoreCsaProfileCrac.query(contextQuery)); + } + return multiContextsPropertyBags; + } +} diff --git a/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileConstants.java b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileConstants.java new file mode 100644 index 0000000000..0bc5d5a319 --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileConstants.java @@ -0,0 +1,72 @@ +/* + * 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/. + */ + +package com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator; + +/** + * @author Jean-Pierre Arnould {@literal } + */ +public final class CsaProfileConstants { + + private CsaProfileConstants() { + } + + /** + * constants to read rdf files + */ + + public static final String EXTENSION_FILE_CSA_PROFILE = "zip"; + + public static final String RDF_BASE_URL = "http://entsoe.eu"; + + public static final String TRIPLESTORE_RDF4J_NAME = "rdf4j"; + + /** + * constants to access triplestore data + */ + + public static final String SPARQL_FILE_CSA_PROFILE = "csa_profile.sparql"; + + /** + * constants to request file headers + */ + + public static final String REQUEST_HEADER_START_DATE = "startDate"; + + public static final String REQUEST_HEADER_END_DATE = "endDate"; + + public static final String REQUEST_HEADER_KEYWORD = "keyword"; + + /** + * constants to request contingencies + */ + + public static final String REQUEST_CONTINGENCY = "contingency"; + + public static final String REQUEST_ORDINARY_CONTINGENCY = "ordinaryContingency"; + + public static final String REQUEST_EXCEPTIONAL_CONTINGENCY = "exceptionalContingency"; + + public static final String REQUEST_OUT_OF_RANGE_CONTINGENCY = "outOfRangeContingency"; + + public static final String REQUEST_CONTINGENCY_EQUIPMENT = "contingencyEquipment"; + + public static final String REQUEST_CONTINGENCIES_NAME = "name"; + + public static final String REQUEST_CONTINGENCIES_EQUIPMENT_OPERATOR = "idEquipmentOperator"; + + public static final String REQUEST_CONTINGENCIES_EQUIPMENT_ID = "contingencyEquipmentId"; + + public static final String REQUEST_CONTINGENCIES_MUST_STUDY = "normalMustStudy"; + + public static final String REQUEST_CONTINGENCIES_CONTINGENT_STATUS = "contingentStatus"; + + public static final String IMPORTED_CONTINGENT_STATUS = "http://iec.ch/TC57/CIM100#ContingencyEquipmentStatusKind.outOfService"; + + public static final String CONTINGENCY_FILE_KEYWORD = "CO"; + +} diff --git a/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileCracCreationContext.java b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileCracCreationContext.java new file mode 100644 index 0000000000..b644ff80d5 --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileCracCreationContext.java @@ -0,0 +1,87 @@ +/* + * 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/. + */ + +package com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator; + +import com.farao_community.farao.data.crac_api.Crac; +import com.farao_community.farao.data.crac_creation.creator.api.CracCreationContext; +import com.farao_community.farao.data.crac_creation.creator.api.CracCreationReport; +import com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator.contingency.CsaProfileContingencyCreationContext; + +import java.time.OffsetDateTime; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * @author Jean-Pierre Arnould {@literal } + */ +public class CsaProfileCracCreationContext implements CracCreationContext { + + private Crac crac; + + private boolean isCreationSuccessful; + + private Set contingencyCreationContexts; + + private final CracCreationReport creationReport; + + private final OffsetDateTime timeStamp; + + private final String networkName; + + CsaProfileCracCreationContext(Crac crac, OffsetDateTime timeStamp, String networkName) { + this.crac = crac; + creationReport = new CracCreationReport(); + this.timeStamp = timeStamp; + this.networkName = networkName; + } + + @Override + public boolean isCreationSuccessful() { + return this.isCreationSuccessful; + } + + @Override + public Crac getCrac() { + return this.crac; + } + + @Override + public OffsetDateTime getTimeStamp() { + return this.timeStamp; + } + + @Override + public String getNetworkName() { + return this.networkName; + } + + public void setContingencyCreationContexts(Set contingencyCreationContexts) { + this.contingencyCreationContexts = contingencyCreationContexts.stream().collect(Collectors.toSet()); + } + + public Set getContingencyCreationContexts() { + return this.contingencyCreationContexts.stream().collect(Collectors.toSet()); + } + + @Override + public CracCreationReport getCreationReport() { + return this.creationReport; + } + + CsaProfileCracCreationContext creationFailure() { + this.isCreationSuccessful = false; + this.crac = null; + return this; + } + + CsaProfileCracCreationContext creationSuccess(Crac crac) { + this.isCreationSuccessful = true; + this.crac = crac; + return this; + } +} diff --git a/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileCracCreator.java b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileCracCreator.java new file mode 100644 index 0000000000..4bc62b845d --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileCracCreator.java @@ -0,0 +1,46 @@ +/* + * 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/. + */ + +package com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator; + +import com.farao_community.farao.data.crac_api.Crac; +import com.farao_community.farao.data.crac_creation.creator.api.CracCreator; +import com.farao_community.farao.data.crac_creation.creator.api.parameters.CracCreationParameters; +import com.farao_community.farao.data.crac_creation.creator.csa_profile.CsaProfileCrac; +import com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator.contingency.CsaProfileContingencyCreator; +import com.powsybl.iidm.network.Network; +import com.powsybl.triplestore.api.PropertyBags; + +import java.time.OffsetDateTime; + +/** + * @author Jean-Pierre Arnould {@literal } + */ +public class CsaProfileCracCreator implements CracCreator { + + private Crac crac; + private Network network; + CsaProfileCracCreationContext creationContext; + + @Override + public String getNativeCracFormat() { + return "CsaProfileCrac"; + } + + public CsaProfileCracCreationContext createCrac(CsaProfileCrac nativeCrac, Network network, OffsetDateTime offsetDateTime, CracCreationParameters cracCreationParameters) { + this.crac = cracCreationParameters.getCracFactory().create(nativeCrac.toString()); + this.network = network; + this.creationContext = new CsaProfileCracCreationContext(crac, offsetDateTime, network.getNameOrId()); + + createContingencies(nativeCrac.getContingencies(), nativeCrac.getContingencyEquipments()); + return creationContext.creationSuccess(crac); + } + + private void createContingencies(PropertyBags contingenciesPropertyBags, PropertyBags contingencyEquipmentsPropertyBags) { + new CsaProfileContingencyCreator(crac, network, contingenciesPropertyBags, contingencyEquipmentsPropertyBags, creationContext); + } +} diff --git a/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileCracUtils.java b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileCracUtils.java new file mode 100644 index 0000000000..3dc9a3b170 --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileCracUtils.java @@ -0,0 +1,45 @@ +/* + * 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/. + */ + +package com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator; + +import com.farao_community.farao.commons.TsoEICode; +import com.powsybl.triplestore.api.PropertyBag; +import com.powsybl.triplestore.api.PropertyBags; + +import java.time.OffsetDateTime; + +/** + * @author Jean-Pierre Arnould {@literal } + */ +public final class CsaProfileCracUtils { + + private CsaProfileCracUtils() { + + } + + public static PropertyBags getLinkedPropertyBags(PropertyBags sources, PropertyBag dest, String sourceProperty, String destProperty) { + PropertyBags linkedBags = new PropertyBags(); + for (PropertyBag source : sources) { + String sourceValue = source.getId(sourceProperty); + if (sourceValue != null && sourceValue.equals(dest.getId(destProperty))) { + linkedBags.add(source); + } + } + return linkedBags; + } + + public static String getUniqueName(String idWithEicCode, String elementId) { + return TsoEICode.fromEICode(idWithEicCode.substring(idWithEicCode.lastIndexOf('/') + 1)).getDisplayName().concat("_").concat(elementId); + } + + public static boolean isValidInterval(OffsetDateTime dateTime, String startTime, String endTime) { + OffsetDateTime startDateTime = OffsetDateTime.parse(startTime); + OffsetDateTime endDateTime = OffsetDateTime.parse(endTime); + return !dateTime.isBefore(startDateTime) && !dateTime.isAfter(endDateTime); + } +} diff --git a/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/contingency/CsaProfileContingencyCreationContext.java b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/contingency/CsaProfileContingencyCreationContext.java new file mode 100644 index 0000000000..1a650a82e0 --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/contingency/CsaProfileContingencyCreationContext.java @@ -0,0 +1,73 @@ +/* + * 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/. + */ + +package com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator.contingency; + +import com.farao_community.farao.data.crac_creation.creator.api.ElementaryCreationContext; +import com.farao_community.farao.data.crac_creation.creator.api.ImportStatus; + +/** + * @author Jean-Pierre Arnould {@literal } + */ +public final class CsaProfileContingencyCreationContext implements ElementaryCreationContext { + private String nativeId; + private String contingencyId; + private String contingencyName; + private ImportStatus importStatus; + private String importStatusDetail; + private boolean isAltered; + + private CsaProfileContingencyCreationContext(String nativeId, String contingencyId, String contingencyName, ImportStatus importStatus, String importStatusDetail, boolean isAltered) { + this.nativeId = nativeId; + this.contingencyId = contingencyId; + this.contingencyName = contingencyName; + this.importStatus = importStatus; + this.importStatusDetail = importStatusDetail; + this.isAltered = isAltered; + } + + public static CsaProfileContingencyCreationContext imported(String nativeId, String contingencyId, String contingencyName, String importStatusDetail, boolean isAltered) { + return new CsaProfileContingencyCreationContext(nativeId, contingencyId, contingencyName, ImportStatus.IMPORTED, importStatusDetail, isAltered); + } + + public static CsaProfileContingencyCreationContext notImported(String nativeId, ImportStatus importStatus, String importStatusDetail) { + return new CsaProfileContingencyCreationContext(nativeId, null, null, importStatus, importStatusDetail, false); + } + + @Override + public String getNativeId() { + return this.nativeId; + } + + public String getContigencyId() { + return this.contingencyId; + } + + public String getNativeName() { + return this.contingencyName; + } + + @Override + public boolean isImported() { + return ImportStatus.IMPORTED.equals(this.importStatus); + } + + @Override + public boolean isAltered() { + return this.isAltered; + } + + @Override + public ImportStatus getImportStatus() { + return this.importStatus; + } + + @Override + public String getImportStatusDetail() { + return this.importStatusDetail; + } +} diff --git a/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/contingency/CsaProfileContingencyCreator.java b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/contingency/CsaProfileContingencyCreator.java new file mode 100644 index 0000000000..1fe3974484 --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/contingency/CsaProfileContingencyCreator.java @@ -0,0 +1,180 @@ +/* + * 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/. + */ + +package com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator.contingency; + +import com.farao_community.farao.data.crac_api.ContingencyAdder; +import com.farao_community.farao.data.crac_api.Crac; +import com.farao_community.farao.data.crac_creation.creator.api.ImportStatus; +import com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator.CsaProfileConstants; +import com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator.CsaProfileCracCreationContext; +import com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator.CsaProfileCracUtils; +import com.farao_community.farao.data.crac_creation.util.cgmes.CgmesBranchHelper; +import com.powsybl.iidm.network.DanglingLine; +import com.powsybl.iidm.network.Identifiable; +import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.TieLine; +import com.powsybl.triplestore.api.PropertyBag; +import com.powsybl.triplestore.api.PropertyBags; + +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; + +/** + * @author Jean-Pierre Arnould {@literal } + */ +public class CsaProfileContingencyCreator { + + private final Crac crac; + + private final Network network; + + private final PropertyBags contingenciesPropertyBags; + + private final PropertyBags contingencyEquipmentsPropertyBags; + + private Set csaProfileContingencyCreationContexts; + private CsaProfileCracCreationContext cracCreationContext; + + public CsaProfileContingencyCreator(Crac crac, Network network, PropertyBags contingenciesPropertyBags, PropertyBags contingencyEquipmentsPropertyBags, CsaProfileCracCreationContext cracCreationContext) { + this.crac = crac; + this.network = network; + this.contingenciesPropertyBags = contingenciesPropertyBags; + this.contingencyEquipmentsPropertyBags = contingencyEquipmentsPropertyBags; + this.cracCreationContext = cracCreationContext; + this.createAndAddContingencies(); + } + + private void createAndAddContingencies() { + this.csaProfileContingencyCreationContexts = new HashSet<>(); + + for (PropertyBag contingencyPropertyBag : contingenciesPropertyBags) { + this.addContingency(contingencyPropertyBag); + } + this.cracCreationContext.setContingencyCreationContexts(csaProfileContingencyCreationContexts); + } + + private void addContingency(PropertyBag contingencyPropertyBag) { + + String contingencyId = contingencyPropertyBag.getId(CsaProfileConstants.REQUEST_CONTINGENCY); + PropertyBags contingencyEquipments = this.dataCheck(contingencyPropertyBag, contingencyId); + if (contingencyEquipments == null) { + return; + } + + String nativeContingencyName = contingencyPropertyBag.get(CsaProfileConstants.REQUEST_CONTINGENCIES_NAME); + String equipmentOperator = contingencyPropertyBag.getId(CsaProfileConstants.REQUEST_CONTINGENCIES_EQUIPMENT_OPERATOR); + String contingencyName = CsaProfileCracUtils.getUniqueName(equipmentOperator, nativeContingencyName); + + ContingencyAdder contingencyAdder = crac.newContingency() + .withId(contingencyId) + .withName(contingencyName); + boolean isIncorrectContingentStatus = false; + boolean isMissingNetworkElement = false; + boolean atLeastOneCorrectContingentStatus = false; + boolean atLeastOneNetworkElement = false; + String incorrectContingentStatusElements = ""; + String missingNetworkElements = ""; + for (PropertyBag contingencyEquipmentPropertyBag : contingencyEquipments) { + String equipmentId = contingencyEquipmentPropertyBag.getId(CsaProfileConstants.REQUEST_CONTINGENCIES_EQUIPMENT_ID); + String contingentStatus = contingencyEquipmentPropertyBag.get(CsaProfileConstants.REQUEST_CONTINGENCIES_CONTINGENT_STATUS); + + if (!CsaProfileConstants.IMPORTED_CONTINGENT_STATUS.equals(contingentStatus)) { + isIncorrectContingentStatus = true; + incorrectContingentStatusElements = incorrectContingentStatusElements.concat(equipmentId + " "); + } else { + atLeastOneCorrectContingentStatus = true; + String networkElementId = this.getNetworkElementIdInNetwork(equipmentId); + if (networkElementId == null) { + isMissingNetworkElement = true; + missingNetworkElements = missingNetworkElements.concat(equipmentId + " "); + } else { + atLeastOneNetworkElement = true; + contingencyAdder.withNetworkElement(networkElementId); + } + } + } + + if (!atLeastOneCorrectContingentStatus) { + csaProfileContingencyCreationContexts.add(CsaProfileContingencyCreationContext.notImported(contingencyId, ImportStatus.INCONSISTENCY_IN_DATA, "all contingency equipments have incorrect contingent status : " + incorrectContingentStatusElements)); + return; + } + + if (!atLeastOneNetworkElement) { + csaProfileContingencyCreationContexts.add(CsaProfileContingencyCreationContext.notImported(contingencyId, ImportStatus.INCONSISTENCY_IN_DATA, "all contingency equipments are missing in network : " + missingNetworkElements)); + return; + } + + contingencyAdder + .add(); + + if (isIncorrectContingentStatus) { + csaProfileContingencyCreationContexts.add(CsaProfileContingencyCreationContext.imported(contingencyId, contingencyId, contingencyName, "incorrect contingent status for equipment(s) : " + incorrectContingentStatusElements, true)); + return; + } + + if (isMissingNetworkElement) { + csaProfileContingencyCreationContexts.add(CsaProfileContingencyCreationContext.imported(contingencyId, contingencyId, contingencyName, "missing contingent equipment(s) in network : " + incorrectContingentStatusElements, true)); + return; + } + + csaProfileContingencyCreationContexts.add(CsaProfileContingencyCreationContext.imported(contingencyId, contingencyId, contingencyName, "", false)); + } + + private PropertyBags dataCheck(PropertyBag contingencyPropertyBag, String contingencyId) { + String keyword = contingencyPropertyBag.get(CsaProfileConstants.REQUEST_HEADER_KEYWORD); + String startTime = contingencyPropertyBag.get(CsaProfileConstants.REQUEST_HEADER_START_DATE); + String endTime = contingencyPropertyBag.get(CsaProfileConstants.REQUEST_HEADER_END_DATE); + + Boolean mustStudy = Boolean.parseBoolean(contingencyPropertyBag.get(CsaProfileConstants.REQUEST_CONTINGENCIES_MUST_STUDY)); + + if (!CsaProfileConstants.CONTINGENCY_FILE_KEYWORD.equals(keyword)) { + csaProfileContingencyCreationContexts.add(CsaProfileContingencyCreationContext.notImported(contingencyId, ImportStatus.INCONSISTENCY_IN_DATA, "Model.keyword must be CO, but it is " + keyword)); + return null; + } + + if (!CsaProfileCracUtils.isValidInterval(cracCreationContext.getTimeStamp(), startTime, endTime)) { + csaProfileContingencyCreationContexts.add(CsaProfileContingencyCreationContext.notImported(contingencyId, ImportStatus.NOT_FOR_REQUESTED_TIMESTAMP, "Required timestamp does not fall between Model.startDate and Model.endDate")); + return null; + } + + if (!mustStudy) { + csaProfileContingencyCreationContexts.add(CsaProfileContingencyCreationContext.notImported(contingencyId, ImportStatus.NOT_FOR_RAO, "contingency.mustStudy is false")); + return null; + } + PropertyBags contingencyEquipments = CsaProfileCracUtils.getLinkedPropertyBags(contingencyEquipmentsPropertyBags, contingencyPropertyBag, CsaProfileConstants.REQUEST_CONTINGENCY, CsaProfileConstants.REQUEST_CONTINGENCY); + if (contingencyEquipments.isEmpty()) { + csaProfileContingencyCreationContexts.add(CsaProfileContingencyCreationContext.notImported(contingencyId, ImportStatus.INCOMPLETE_DATA, "no contingency equipment linked to the contingency")); + return null; + } + + return contingencyEquipments; + } + + private String getNetworkElementIdInNetwork(String networkElementIdInCrac) { + String networkElementId = null; + Identifiable networkElement = network.getIdentifiable(networkElementIdInCrac); + if (networkElement == null) { + CgmesBranchHelper cgmesBranchHelper = new CgmesBranchHelper(networkElementIdInCrac, network); + if (cgmesBranchHelper.isValid()) { + networkElementId = cgmesBranchHelper.getIdInNetwork(); + networkElement = cgmesBranchHelper.getBranch(); + } + } else { + networkElementId = networkElement.getId(); + } + + if (networkElement instanceof DanglingLine) { + Optional optionalTieLine = ((DanglingLine) networkElement).getTieLine(); + if (optionalTieLine.isPresent()) { + networkElementId = optionalTieLine.get().getId(); + } + } + return networkElementId; + } +} diff --git a/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/importer/CsaProfileCracImporter.java b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/importer/CsaProfileCracImporter.java new file mode 100644 index 0000000000..dce2624bce --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/src/main/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/importer/CsaProfileCracImporter.java @@ -0,0 +1,76 @@ +/* + * 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/. + */ + +package com.farao_community.farao.data.crac_creation.creator.csa_profile.importer; + +import com.farao_community.farao.commons.logs.FaraoLoggerProvider; +import com.farao_community.farao.data.crac_creation.creator.csa_profile.CsaProfileCrac; +import com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator.CsaProfileConstants; +import com.farao_community.farao.data.native_crac_io_api.NativeCracImporter; +import com.google.auto.service.AutoService; +import com.powsybl.triplestore.api.TripleStore; +import com.powsybl.triplestore.api.TripleStoreFactory; +import org.apache.commons.io.FilenameUtils; + +import java.io.*; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +/** + * @author Jean-Pierre Arnould {@literal } + */ +@AutoService(NativeCracImporter.class) +public class CsaProfileCracImporter implements NativeCracImporter { + + @Override + public String getFormat() { + return "CsaProfileCrac"; + } + + /** + * @param inputStream : zip file inputStream + * @return csa profile native crac, the tripleStore contains data of every rdf file included in the zip + * each context of the tripleStore contains one rdf file data + */ + @Override + public CsaProfileCrac importNativeCrac(InputStream inputStream) { + TripleStore tripleStoreCsaProfile = TripleStoreFactory.create(CsaProfileConstants.TRIPLESTORE_RDF4J_NAME); + ZipInputStream zipInputStream = new ZipInputStream(inputStream); + ZipEntry zipEntry; + try { + zipInputStream.getNextEntry(); + while ((zipEntry = zipInputStream.getNextEntry()) != null) { + if (!zipEntry.isDirectory()) { + FaraoLoggerProvider.BUSINESS_LOGS.info("csa profile crac import : import of file {}", zipEntry.getName()); + File tempFile = File.createTempFile("faraoCsaProfile", ".tmp"); + FileOutputStream outputStream = new FileOutputStream(tempFile); + zipInputStream.transferTo(outputStream); + outputStream.close(); + FileInputStream fileInputStream = new FileInputStream(tempFile); + tripleStoreCsaProfile.read(fileInputStream, CsaProfileConstants.RDF_BASE_URL, zipEntry.getName()); + if (!tempFile.delete()) { + FaraoLoggerProvider.TECHNICAL_LOGS.warn("temporary file for csa profile crac import can't be deleted"); + tempFile.deleteOnExit(); + } + } + } + zipInputStream.close(); + inputStream.close(); + } catch (IOException e) { + FaraoLoggerProvider.TECHNICAL_LOGS.error("csa profile crac import interrupted, cause : {}", e.getMessage()); + } + + return new CsaProfileCrac(tripleStoreCsaProfile); + } + + @Override + public boolean exists(String fileName, InputStream inputStream) { + TripleStore tripleStoreCsaProfile = TripleStoreFactory.create(CsaProfileConstants.TRIPLESTORE_RDF4J_NAME); + tripleStoreCsaProfile.read(inputStream, CsaProfileConstants.RDF_BASE_URL, ""); + return tripleStoreCsaProfile != null && FilenameUtils.getExtension(fileName).equals(CsaProfileConstants.EXTENSION_FILE_CSA_PROFILE); + } +} diff --git a/data/crac-creation/crac-creator-csa-profiles/src/main/resources/csa_profile.sparql b/data/crac-creation/crac-creator-csa-profiles/src/main/resources/csa_profile.sparql new file mode 100644 index 0000000000..e77c5df943 --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/src/main/resources/csa_profile.sparql @@ -0,0 +1,74 @@ +# +# 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/. +# + +# query: contingencyEquipment +PREFIX cim: +SELECT * +WHERE { + ?contingencyEquipment + rdf:type cim:ContingencyEquipment ; + cim:ContingencyEquipment.Equipment ?contingencyEquipmentId ; + cim:ContingencyElement.Contingency ?contingency ; + cim:ContingencyEquipment.contingentStatus ?contingentStatus ; +} + +# query: ordinaryContingency +PREFIX cim: +PREFIX nc: +PREFIX dcat: +SELECT * +{ +GRAPH <%s> { + ?fullModel + dcat:Model.startDate ?startDate ; + dcat:Model.endDate ?endDate ; + dcat:Model.keyword ?keyword . + ?contingency + rdf:type nc:OrdinaryContingency ; + cim:IdentifiedObject.name ?name ; + nc:Contingency.EquipmentOperator ?idEquipmentOperator ; + nc:Contingency.normalMustStudy ?normalMustStudy ; +} +} + +# query: exceptionalContingency +PREFIX cim: +PREFIX nc: +PREFIX dcat: +SELECT * +{ +GRAPH <%s> { + ?fullModel + dcat:Model.startDate ?startDate ; + dcat:Model.endDate ?endDate ; + dcat:Model.keyword ?keyword . + ?contingency + rdf:type nc:ExceptionalContingency ; + cim:IdentifiedObject.name ?name ; + nc:Contingency.EquipmentOperator ?idEquipmentOperator ; + nc:Contingency.normalMustStudy ?normalMustStudy ; +} +} + +# query: outOfRangeContingency +PREFIX cim: +PREFIX nc: +PREFIX dcat: +SELECT * +{ +GRAPH <%s> { + ?fullModel + dcat:Model.startDate ?startDate ; + dcat:Model.endDate ?endDate ; + dcat:Model.keyword ?keyword . + ?contingency + rdf:type nc:OutOfRangeContingency ; + cim:IdentifiedObject.name ?name ; + nc:Contingency.EquipmentOperator ?idEquipmentOperator ; + nc:Contingency.normalMustStudy ?normalMustStudy ; +} +} \ No newline at end of file diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileCracCreatorTest.java b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileCracCreatorTest.java new file mode 100644 index 0000000000..1cb8dbe54b --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileCracCreatorTest.java @@ -0,0 +1,206 @@ +/* + * 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/. + */ + +package com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator; + +import com.farao_community.farao.data.crac_api.Contingency; +import com.farao_community.farao.data.crac_api.NetworkElement; +import com.farao_community.farao.data.crac_creation.creator.api.parameters.CracCreationParameters; +import com.farao_community.farao.data.crac_creation.creator.csa_profile.CsaProfileCrac; +import com.farao_community.farao.data.crac_creation.creator.csa_profile.importer.CsaProfileCracImporter; +import com.google.common.base.Suppliers; +import com.powsybl.computation.local.LocalComputationManager; +import com.powsybl.iidm.network.ImportConfig; +import com.powsybl.iidm.network.Network; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.io.InputStream; +import java.nio.file.Paths; +import java.time.OffsetDateTime; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.Properties; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.*; + +public class CsaProfileCracCreatorTest { + + @Test + public void testCreateCracTestConfigurationTC1v29Mar2023() { + Properties importParams = new Properties(); + Network network = Network.read(Paths.get(new File(CsaProfileCracCreatorTest.class.getResource("/TestConfiguration_TC1_v29Mar2023.zip").getFile()).toString()), LocalComputationManager.getDefault(), Suppliers.memoize(ImportConfig::load).get(), importParams); + + CsaProfileCracImporter cracImporter = new CsaProfileCracImporter(); + InputStream inputStream = getClass().getResourceAsStream("/TestConfiguration_TC1_v29Mar2023.zip"); + CsaProfileCrac nativeCrac = cracImporter.importNativeCrac(inputStream); + + CsaProfileCracCreator cracCreator = new CsaProfileCracCreator(); + CsaProfileCracCreationContext cracCreationContext = cracCreator.createCrac(nativeCrac, network, OffsetDateTime.parse("2023-03-29T12:00Z"), new CracCreationParameters()); + + assertNotNull(cracCreationContext); + assertTrue(cracCreationContext.isCreationSuccessful()); + assertEquals(2, cracCreationContext.getCrac().getContingencies().size()); + List listContingencies = cracCreationContext.getCrac().getContingencies() + .stream().sorted(Comparator.comparing(Contingency::getId)).collect(Collectors.toList()); + + this.assertContingencyEquality(listContingencies.get(0), + "493480ba-93c3-426e-bee5-347d8dda3749", "ELIA_CO1", + 1, Arrays.asList("17086487-56ba-4979-b8de-064025a6b4da + 8fdc7abd-3746-481a-a65e-3df56acd8b13")); + this.assertContingencyEquality(listContingencies.get(1), + "c0a25fd7-eee0-4191-98a5-71a74469d36e", "TENNET_TSO_CO1", + 1, Arrays.asList("b18cd1aa-7808-49b9-a7cf-605eaf07b006 + e8acf6b6-99cb-45ad-b8dc-16c7866a4ddc")); + } + + @Test + public void testCreateCracCSATestConfigurationTC2Draftv14Apr2023() { + CsaProfileCracImporter cracImporter = new CsaProfileCracImporter(); + InputStream inputStream = getClass().getResourceAsStream("/CSA_TestConfiguration_TC2_Draft_v14Apr2023.zip"); + CsaProfileCrac nativeCrac = cracImporter.importNativeCrac(inputStream); + + Properties importParams = new Properties(); + Network network = Network.read(Paths.get(new File(CsaProfileCracCreatorTest.class.getResource("/CSA_TestConfiguration_TC2_Draft_v14Apr2023.zip").getFile()).toString()), LocalComputationManager.getDefault(), Suppliers.memoize(ImportConfig::load).get(), importParams); + + CsaProfileCracCreator cracCreator = new CsaProfileCracCreator(); + CsaProfileCracCreationContext cracCreationContext = cracCreator.createCrac(nativeCrac, network, OffsetDateTime.parse("2023-03-29T12:00Z"), new CracCreationParameters()); + + assertNotNull(cracCreationContext); + assertTrue(cracCreationContext.isCreationSuccessful()); + assertEquals(15, cracCreationContext.getCrac().getContingencies().size()); + + List listContingencies = cracCreationContext.getCrac().getContingencies() + .stream().sorted(Comparator.comparing(Contingency::getId)).collect(Collectors.toList()); + + this.assertContingencyEquality(listContingencies.get(0), + "13334fdf-9cc2-4341-adb6-1281269040b4", "REE_CO3", + 2, Arrays.asList("04566cf8-c766-11e1-8775-005056c00008", "0475dbd8-c766-11e1-8775-005056c00008")); + this.assertContingencyEquality(listContingencies.get(1), + "264e9a19-ae28-4c85-a43c-6b7818ca0e6c", "RTE_CO4", + 1, Arrays.asList("536f4b84-db4c-4545-96e9-bb5a87f65d13 + d9622e7f-5bf0-4e7e-b766-b8596c6fe4ae")); + this.assertContingencyEquality(listContingencies.get(2), + "37997e71-cb7d-4a8c-baa6-2a1594956da9", "ELIA_CO3", + 1, Arrays.asList("550ebe0d-f2b2-48c1-991f-cebea43a21aa")); + this.assertContingencyEquality(listContingencies.get(3), + "475ba18f-cbf5-490b-b65d-e8e03f9bcbc4", "RTE_CO2", + 1, Arrays.asList("e02e1166-1c43-4a4d-8c5a-82298ee0c8f5")); + this.assertContingencyEquality(listContingencies.get(4), + "5d587c7e-9ced-416a-ad17-6ef9b241a998", "RTE_CO3", + 1, Arrays.asList("2ab1b800-0c93-4517-86b5-8fd6a3a24ee7")); + this.assertContingencyEquality(listContingencies.get(5), + "7e31c67d-67ba-4592-8ac1-9e806d697c8e", "ELIA_CO2", + 1, Arrays.asList("536f4b84-db4c-4545-96e9-bb5a87f65d13 + d9622e7f-5bf0-4e7e-b766-b8596c6fe4ae")); + this.assertContingencyEquality(listContingencies.get(6), + "8cdec4c6-10c3-40c1-9eeb-7f6ae8d9b3fe", "REE_CO1", + 1, Arrays.asList("044bbe91-c766-11e1-8775-005056c00008")); + this.assertContingencyEquality(listContingencies.get(7), + "96c96ad8-844c-4f3b-8b38-c886ba2c0214", "REE_CO5", + 1, Arrays.asList("891e77ff-39c6-4648-8eda-d81f730271f9 + a04e4e41-c0b4-496e-9ef3-390ea089411f")); + this.assertContingencyEquality(listContingencies.get(8), + "9d17b84c-33b5-4a68-b8b9-ed5b31038d40", "REE_CO4", + 2, Arrays.asList("04566cf8-c766-11e1-8775-005056c00008", "0475dbd8-c766-11e1-8775-005056c00008")); + this.assertContingencyEquality(listContingencies.get(9), + "b6b780cb-9fe5-4c45-989d-447a927c3874", "REE_CO2", + 1, Arrays.asList("048481d0-c766-11e1-8775-005056c00008")); + this.assertContingencyEquality(listContingencies.get(10), + "bd7bb012-f7b9-45e0-9e15-4e2aa3592829", "TENNET_TSO_CO3", + 1, Arrays.asList("9c3b8f97-7972-477d-9dc8-87365cc0ad0e")); + this.assertContingencyEquality(listContingencies.get(11), + "ce19dd34-429e-4b72-8813-7615cc57b4a4", "RTE_CO6", + 1, Arrays.asList("04839777-c766-11e1-8775-005056c00008")); + this.assertContingencyEquality(listContingencies.get(12), + "d9ef0d5e-732d-441e-9611-c817b0afbc41", "RTE_CO5", + 1, Arrays.asList("f0dee14e-aa43-411e-a2ea-b9879c20f3be")); + this.assertContingencyEquality(listContingencies.get(13), + "e05bbe20-9d4a-40da-9777-8424d216785d", "RTE_CO1", + 1, Arrays.asList("f1c13f90-6d89-4a37-a51c-94742ad2dd72")); + this.assertContingencyEquality(listContingencies.get(14), + "e9eab3fe-c328-4f78-9bc1-77adb59f6ba7", "ELIA_CO1", + 1, Arrays.asList("dad02278-bd25-476f-8f58-dbe44be72586 + ed0c5d75-4a54-43c8-b782-b20d7431630b")); + } + + @Test + public void testCreateCracCSATestWithRejectedFiles() { + CsaProfileCracImporter cracImporter = new CsaProfileCracImporter(); + InputStream inputStream = getClass().getResourceAsStream("/CSA_Test_With_Rejected_Files.zip"); + CsaProfileCrac nativeCrac = cracImporter.importNativeCrac(inputStream); + + Properties importParams = new Properties(); + Network network = Network.read(Paths.get(new File(CsaProfileCracCreatorTest.class.getResource("/CSA_Test_With_Rejected_Files.zip").getFile()).toString()), LocalComputationManager.getDefault(), Suppliers.memoize(ImportConfig::load).get(), importParams); + + CsaProfileCracCreator cracCreator = new CsaProfileCracCreator(); + CsaProfileCracCreationContext cracCreationContext = cracCreator.createCrac(nativeCrac, network, OffsetDateTime.parse("2023-03-29T12:00Z"), new CracCreationParameters()); + + assertNotNull(cracCreationContext); + assertTrue(cracCreationContext.isCreationSuccessful()); + assertEquals(7, cracCreationContext.getCrac().getContingencies().size()); + List listContingencies = cracCreationContext.getCrac().getContingencies() + .stream().sorted(Comparator.comparing(Contingency::getId)).collect(Collectors.toList()); + + this.assertContingencyEquality(listContingencies.get(0), + "264e9a19-ae28-4c85-a43c-6b7818ca0e6c", "RTE_CO4", + 1, Arrays.asList("536f4b84-db4c-4545-96e9-bb5a87f65d13 + d9622e7f-5bf0-4e7e-b766-b8596c6fe4ae")); + this.assertContingencyEquality(listContingencies.get(1), + "475ba18f-cbf5-490b-b65d-e8e03f9bcbc4", "RTE_CO2", + 1, Arrays.asList("e02e1166-1c43-4a4d-8c5a-82298ee0c8f5")); + this.assertContingencyEquality(listContingencies.get(2), + "5d587c7e-9ced-416a-ad17-6ef9b241a998", "RTE_CO3", + 1, Arrays.asList("2ab1b800-0c93-4517-86b5-8fd6a3a24ee7")); + this.assertContingencyEquality(listContingencies.get(3), + "bd7bb012-f7b9-45e0-9e15-4e2aa3592829", "TENNET_TSO_CO3", + 1, Arrays.asList("9c3b8f97-7972-477d-9dc8-87365cc0ad0e")); + this.assertContingencyEquality(listContingencies.get(4), + "ce19dd34-429e-4b72-8813-7615cc57b4a4", "RTE_CO6", + 1, Arrays.asList("04839777-c766-11e1-8775-005056c00008")); + this.assertContingencyEquality(listContingencies.get(5), + "d9ef0d5e-732d-441e-9611-c817b0afbc41", "RTE_CO5", + 1, Arrays.asList("f0dee14e-aa43-411e-a2ea-b9879c20f3be")); + this.assertContingencyEquality(listContingencies.get(6), + "e05bbe20-9d4a-40da-9777-8424d216785d", "RTE_CO1", + 1, Arrays.asList("f1c13f90-6d89-4a37-a51c-94742ad2dd72")); + + } + + @Test + public void testCreateCracCSATestWithRefusedContingencies() { + CsaProfileCracImporter cracImporter = new CsaProfileCracImporter(); + InputStream inputStream = getClass().getResourceAsStream("/Test_With_Refused_Contingencies.zip"); + CsaProfileCrac nativeCrac = cracImporter.importNativeCrac(inputStream); + + Properties importParams = new Properties(); + Network network = Network.read(Paths.get(new File(CsaProfileCracCreatorTest.class.getResource("/Test_With_Refused_Contingencies.zip").getFile()).toString()), LocalComputationManager.getDefault(), Suppliers.memoize(ImportConfig::load).get(), importParams); + + CsaProfileCracCreator cracCreator = new CsaProfileCracCreator(); + CsaProfileCracCreationContext cracCreationContext = cracCreator.createCrac(nativeCrac, network, OffsetDateTime.parse("2023-03-29T12:00Z"), new CracCreationParameters()); + + assertNotNull(cracCreationContext); + assertTrue(cracCreationContext.isCreationSuccessful()); + assertEquals(2, cracCreationContext.getCrac().getContingencies().size()); + List listContingencies = cracCreationContext.getCrac().getContingencies() + .stream().sorted(Comparator.comparing(Contingency::getId)).collect(Collectors.toList()); + + this.assertContingencyEquality(listContingencies.get(0), + "493480ba-93c3-426e-bee5-347d8dda3749", "ELIA_CO1", + 1, Arrays.asList("17086487-56ba-4979-b8de-064025a6b4da + 8fdc7abd-3746-481a-a65e-3df56acd8b13")); + this.assertContingencyEquality(listContingencies.get(1), + "c0a25fd7-eee0-4191-98a5-71a74469d36e", "TENNET_TSO_CO1", + 1, Arrays.asList("b18cd1aa-7808-49b9-a7cf-605eaf07b006 + e8acf6b6-99cb-45ad-b8dc-16c7866a4ddc")); + } + + private void assertContingencyEquality(Contingency c, String expectedContingencyId, String expectedContingecyName, int expectedNetworkElementsSize, List expectedNetworkElementsIds) { + assertEquals(expectedContingencyId, c.getId()); + assertEquals(expectedContingecyName, c.getName()); + List networkElements = c.getNetworkElements().stream() + .sorted(Comparator.comparing(NetworkElement::getId)).collect(Collectors.toList()); + assertEquals(expectedNetworkElementsSize, networkElements.size()); + for (int i = 0; i < expectedNetworkElementsSize; i++) { + assertEquals(expectedNetworkElementsIds.get(i), networkElements.get(i).getId()); + } + + } +} diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileCracUtilsTest.java b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileCracUtilsTest.java new file mode 100644 index 0000000000..4ef124b010 --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/crac_creator/CsaProfileCracUtilsTest.java @@ -0,0 +1,57 @@ +/* + * 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/. + */ + +package com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator; + +import com.powsybl.triplestore.api.PropertyBag; +import com.powsybl.triplestore.api.PropertyBags; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class CsaProfileCracUtilsTest { + + @Test + public void testGetLinkedPropertyBags() { + List listPropDest = Arrays.asList("destProperty1", "destProperty2", "destProperty3", "destProperty4"); + List listPropSource = Arrays.asList("sourceProperty1", "sourceProperty2", "sourceProperty3", "sourceProperty4"); + PropertyBag destPb = new PropertyBag(listPropDest, false); + destPb.put("destProperty1", "destValue1"); + destPb.put("destProperty2", "destValue2"); + destPb.put("destProperty3", "http://blablabla.eu/#_destValue3"); + destPb.put("destProperty4", "destValue4"); + + PropertyBags sourcesPb = new PropertyBags(); + PropertyBag sourcePb1 = new PropertyBag(listPropSource, false); + sourcePb1.put("sourceProperty1", "sourceValue11"); + sourcePb1.put("sourceProperty2", "_destValue3"); + sourcePb1.put("sourceProperty3", "sourceValue13"); + sourcePb1.put("sourceProperty4", "sourceValue14"); + + PropertyBag sourcePb2 = new PropertyBag(listPropSource, false); + sourcePb2.put("sourceProperty1", "sourceValue21"); + sourcePb2.put("sourceProperty3", "sourceValue23"); + sourcePb2.put("sourceProperty4", "sourceValue24"); + + PropertyBag sourcePb3 = new PropertyBag(listPropSource, false); + sourcePb3.put("sourceProperty1", "sourceValue31"); + sourcePb3.put("sourceProperty2", "sourceValue32"); + sourcePb3.put("sourceProperty3", "sourceValue33"); + sourcePb3.put("sourceProperty4", "sourceValue34"); + + sourcesPb.addAll(Arrays.asList(sourcePb1, sourcePb2, sourcePb3)); + + PropertyBags result = CsaProfileCracUtils.getLinkedPropertyBags(sourcesPb, destPb, "sourceProperty2", "destProperty3"); + assertNotNull(result); + assertEquals(1, result.size()); + assertEquals("sourceValue11", result.get(0).get("sourceProperty1")); + } +} diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/importer/CsaProfileCracImporterTest.java b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/importer/CsaProfileCracImporterTest.java new file mode 100644 index 0000000000..f9974ba6c4 --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/src/test/java/com/farao_community/farao/data/crac_creation/creator/csa_profile/importer/CsaProfileCracImporterTest.java @@ -0,0 +1,55 @@ +/* + * 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/. + */ + +package com.farao_community.farao.data.crac_creation.creator.csa_profile.importer; + +import com.farao_community.farao.data.crac_creation.creator.csa_profile.CsaProfileCrac; +import com.farao_community.farao.data.crac_creation.creator.csa_profile.crac_creator.CsaProfileConstants; +import com.powsybl.triplestore.api.PropertyBags; +import org.junit.jupiter.api.Test; + +import java.io.InputStream; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * @author Jean-Pierre Arnould {@literal } + */ +public class CsaProfileCracImporterTest { + + @Test + void getFormat() { + CsaProfileCracImporter csaProfileCracImporter = new CsaProfileCracImporter(); + assertEquals("CsaProfileCrac", csaProfileCracImporter.getFormat()); + } + + @Test + void testImportNativeCrac() { + CsaProfileCracImporter csaProfileCracImporter = new CsaProfileCracImporter(); + InputStream is1 = getClass().getResourceAsStream("/TestConfiguration_TC1_v29Mar2023.zip"); + CsaProfileCrac csaProfileCrac = csaProfileCracImporter.importNativeCrac(is1); + assertNotNull(csaProfileCrac); + PropertyBags contingenciesPb = csaProfileCrac.getContingencies(); + assertNotNull(contingenciesPb); + assertEquals(2, contingenciesPb.size()); + assertEquals("493480ba-93c3-426e-bee5-347d8dda3749", contingenciesPb.get(0).getId(CsaProfileConstants.REQUEST_CONTINGENCY)); + assertEquals("c0a25fd7-eee0-4191-98a5-71a74469d36e", contingenciesPb.get(1).getId(CsaProfileConstants.REQUEST_CONTINGENCY)); + + PropertyBags contingencyEquipmentsPb = csaProfileCrac.getContingencyEquipments(); + assertNotNull(contingencyEquipmentsPb); + assertEquals(2, contingencyEquipmentsPb.size()); + assertEquals("ef11f9bd-5da0-43e3-921b-7e92d2896136", contingencyEquipmentsPb.get(0).getId(CsaProfileConstants.REQUEST_CONTINGENCY_EQUIPMENT)); + assertEquals("f19925fa-b114-48c5-97a4-42ef84372115", contingencyEquipmentsPb.get(1).getId(CsaProfileConstants.REQUEST_CONTINGENCY_EQUIPMENT)); + } + + @Test + void testExists() { + InputStream is1 = getClass().getResourceAsStream("/TestConfiguration_TC1_v29Mar2023.zip"); + CsaProfileCracImporter importer = new CsaProfileCracImporter(); + assertTrue(importer.exists("TestConfiguration_TC1_v29Mar2023.zip", is1)); + } +} diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/resources/CSA_TestConfiguration_TC2_Draft_v14Apr2023.zip b/data/crac-creation/crac-creator-csa-profiles/src/test/resources/CSA_TestConfiguration_TC2_Draft_v14Apr2023.zip new file mode 100644 index 0000000000..f64b1722ab Binary files /dev/null and b/data/crac-creation/crac-creator-csa-profiles/src/test/resources/CSA_TestConfiguration_TC2_Draft_v14Apr2023.zip differ diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/resources/CSA_Test_With_Rejected_Files.zip b/data/crac-creation/crac-creator-csa-profiles/src/test/resources/CSA_Test_With_Rejected_Files.zip new file mode 100644 index 0000000000..a1fe998692 Binary files /dev/null and b/data/crac-creation/crac-creator-csa-profiles/src/test/resources/CSA_Test_With_Rejected_Files.zip differ diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/resources/Disclaimer.txt b/data/crac-creation/crac-creator-csa-profiles/src/test/resources/Disclaimer.txt new file mode 100644 index 0000000000..2145bc1ccf --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/src/test/resources/Disclaimer.txt @@ -0,0 +1 @@ +Disclaimer The test configurations (models), documents and application profiles are owned by ENTSO-E and are provided by ENTSO-E “as it is”. To the fullest extent permitted by law, ENTSO-E shall not be liable for any damages of any kind arising out of the use of the test configurations (models), documents and application profiles (including any of their subsequent modifications). ENTSO-E neither warrants, nor represents that the use of the test configurations (models), documents and application profiles will not infringe the rights of third parties. Any use of the test configurations (models), documents and application profiles shall include a reference to ENTSO-E. ENTSO-E web site is the only official source of information related to these test configurations (models), documents and application profiles. \ No newline at end of file diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/resources/LICENSE.txt b/data/crac-creation/crac-creator-csa-profiles/src/test/resources/LICENSE.txt new file mode 100644 index 0000000000..cbe5ad1670 --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/src/test/resources/LICENSE.txt @@ -0,0 +1,437 @@ +Attribution-NonCommercial-ShareAlike 4.0 International + +======================================================================= + +Creative Commons Corporation ("Creative Commons") is not a law firm and +does not provide legal services or legal advice. Distribution of +Creative Commons public licenses does not create a lawyer-client or +other relationship. Creative Commons makes its licenses and related +information available on an "as-is" basis. Creative Commons gives no +warranties regarding its licenses, any material licensed under their +terms and conditions, or any related information. Creative Commons +disclaims all liability for damages resulting from their use to the +fullest extent possible. + +Using Creative Commons Public Licenses + +Creative Commons public licenses provide a standard set of terms and +conditions that creators and other rights holders may use to share +original works of authorship and other material subject to copyright +and certain other rights specified in the public license below. The +following considerations are for informational purposes only, are not +exhaustive, and do not form part of our licenses. + + Considerations for licensors: Our public licenses are + intended for use by those authorized to give the public + permission to use material in ways otherwise restricted by + copyright and certain other rights. Our licenses are + irrevocable. Licensors should read and understand the terms + and conditions of the license they choose before applying it. + Licensors should also secure all rights necessary before + applying our licenses so that the public can reuse the + material as expected. Licensors should clearly mark any + material not subject to the license. This includes other CC- + licensed material, or material used under an exception or + limitation to copyright. More considerations for licensors: + wiki.creativecommons.org/Considerations_for_licensors + + Considerations for the public: By using one of our public + licenses, a licensor grants the public permission to use the + licensed material under specified terms and conditions. If + the licensor's permission is not necessary for any reason--for + example, because of any applicable exception or limitation to + copyright--then that use is not regulated by the license. Our + licenses grant only permissions under copyright and certain + other rights that a licensor has authority to grant. Use of + the licensed material may still be restricted for other + reasons, including because others have copyright or other + rights in the material. A licensor may make special requests, + such as asking that all changes be marked or described. + Although not required by our licenses, you are encouraged to + respect those requests where reasonable. More considerations + for the public: + wiki.creativecommons.org/Considerations_for_licensees + +======================================================================= + +Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International +Public License + +By exercising the Licensed Rights (defined below), You accept and agree +to be bound by the terms and conditions of this Creative Commons +Attribution-NonCommercial-ShareAlike 4.0 International Public License +("Public License"). To the extent this Public License may be +interpreted as a contract, You are granted the Licensed Rights in +consideration of Your acceptance of these terms and conditions, and the +Licensor grants You such rights in consideration of benefits the +Licensor receives from making the Licensed Material available under +these terms and conditions. + + +Section 1 -- Definitions. + + a. Adapted Material means material subject to Copyright and Similar + Rights that is derived from or based upon the Licensed Material + and in which the Licensed Material is translated, altered, + arranged, transformed, or otherwise modified in a manner requiring + permission under the Copyright and Similar Rights held by the + Licensor. For purposes of this Public License, where the Licensed + Material is a musical work, performance, or sound recording, + Adapted Material is always produced where the Licensed Material is + synched in timed relation with a moving image. + + b. Adapter's License means the license You apply to Your Copyright + and Similar Rights in Your contributions to Adapted Material in + accordance with the terms and conditions of this Public License. + + c. BY-NC-SA Compatible License means a license listed at + creativecommons.org/compatiblelicenses, approved by Creative + Commons as essentially the equivalent of this Public License. + + d. Copyright and Similar Rights means copyright and/or similar rights + closely related to copyright including, without limitation, + performance, broadcast, sound recording, and Sui Generis Database + Rights, without regard to how the rights are labeled or + categorized. For purposes of this Public License, the rights + specified in Section 2(b)(1)-(2) are not Copyright and Similar + Rights. + + e. Effective Technological Measures means those measures that, in the + absence of proper authority, may not be circumvented under laws + fulfilling obligations under Article 11 of the WIPO Copyright + Treaty adopted on December 20, 1996, and/or similar international + agreements. + + f. Exceptions and Limitations means fair use, fair dealing, and/or + any other exception or limitation to Copyright and Similar Rights + that applies to Your use of the Licensed Material. + + g. License Elements means the license attributes listed in the name + of a Creative Commons Public License. The License Elements of this + Public License are Attribution, NonCommercial, and ShareAlike. + + h. Licensed Material means the artistic or literary work, database, + or other material to which the Licensor applied this Public + License. + + i. Licensed Rights means the rights granted to You subject to the + terms and conditions of this Public License, which are limited to + all Copyright and Similar Rights that apply to Your use of the + Licensed Material and that the Licensor has authority to license. + + j. Licensor means the individual(s) or entity(ies) granting rights + under this Public License. + + k. NonCommercial means not primarily intended for or directed towards + commercial advantage or monetary compensation. For purposes of + this Public License, the exchange of the Licensed Material for + other material subject to Copyright and Similar Rights by digital + file-sharing or similar means is NonCommercial provided there is + no payment of monetary compensation in connection with the + exchange. + + l. Share means to provide material to the public by any means or + process that requires permission under the Licensed Rights, such + as reproduction, public display, public performance, distribution, + dissemination, communication, or importation, and to make material + available to the public including in ways that members of the + public may access the material from a place and at a time + individually chosen by them. + + m. Sui Generis Database Rights means rights other than copyright + resulting from Directive 96/9/EC of the European Parliament and of + the Council of 11 March 1996 on the legal protection of databases, + as amended and/or succeeded, as well as other essentially + equivalent rights anywhere in the world. + + n. You means the individual or entity exercising the Licensed Rights + under this Public License. Your has a corresponding meaning. + + +Section 2 -- Scope. + + a. License grant. + + 1. Subject to the terms and conditions of this Public License, + the Licensor hereby grants You a worldwide, royalty-free, + non-sublicensable, non-exclusive, irrevocable license to + exercise the Licensed Rights in the Licensed Material to: + + a. reproduce and Share the Licensed Material, in whole or + in part, for NonCommercial purposes only; and + + b. produce, reproduce, and Share Adapted Material for + NonCommercial purposes only. + + 2. Exceptions and Limitations. For the avoidance of doubt, where + Exceptions and Limitations apply to Your use, this Public + License does not apply, and You do not need to comply with + its terms and conditions. + + 3. Term. The term of this Public License is specified in Section + 6(a). + + 4. Media and formats; technical modifications allowed. The + Licensor authorizes You to exercise the Licensed Rights in + all media and formats whether now known or hereafter created, + and to make technical modifications necessary to do so. The + Licensor waives and/or agrees not to assert any right or + authority to forbid You from making technical modifications + necessary to exercise the Licensed Rights, including + technical modifications necessary to circumvent Effective + Technological Measures. For purposes of this Public License, + simply making modifications authorized by this Section 2(a) + (4) never produces Adapted Material. + + 5. Downstream recipients. + + a. Offer from the Licensor -- Licensed Material. Every + recipient of the Licensed Material automatically + receives an offer from the Licensor to exercise the + Licensed Rights under the terms and conditions of this + Public License. + + b. Additional offer from the Licensor -- Adapted Material. + Every recipient of Adapted Material from You + automatically receives an offer from the Licensor to + exercise the Licensed Rights in the Adapted Material + under the conditions of the Adapter's License You apply. + + c. No downstream restrictions. You may not offer or impose + any additional or different terms or conditions on, or + apply any Effective Technological Measures to, the + Licensed Material if doing so restricts exercise of the + Licensed Rights by any recipient of the Licensed + Material. + + 6. No endorsement. Nothing in this Public License constitutes or + may be construed as permission to assert or imply that You + are, or that Your use of the Licensed Material is, connected + with, or sponsored, endorsed, or granted official status by, + the Licensor or others designated to receive attribution as + provided in Section 3(a)(1)(A)(i). + + b. Other rights. + + 1. Moral rights, such as the right of integrity, are not + licensed under this Public License, nor are publicity, + privacy, and/or other similar personality rights; however, to + the extent possible, the Licensor waives and/or agrees not to + assert any such rights held by the Licensor to the limited + extent necessary to allow You to exercise the Licensed + Rights, but not otherwise. + + 2. Patent and trademark rights are not licensed under this + Public License. + + 3. To the extent possible, the Licensor waives any right to + collect royalties from You for the exercise of the Licensed + Rights, whether directly or through a collecting society + under any voluntary or waivable statutory or compulsory + licensing scheme. In all other cases the Licensor expressly + reserves any right to collect such royalties, including when + the Licensed Material is used other than for NonCommercial + purposes. + + +Section 3 -- License Conditions. + +Your exercise of the Licensed Rights is expressly made subject to the +following conditions. + + a. Attribution. + + 1. If You Share the Licensed Material (including in modified + form), You must: + + a. retain the following if it is supplied by the Licensor + with the Licensed Material: + + i. identification of the creator(s) of the Licensed + Material and any others designated to receive + attribution, in any reasonable manner requested by + the Licensor (including by pseudonym if + designated); + + ii. a copyright notice; + + iii. a notice that refers to this Public License; + + iv. a notice that refers to the disclaimer of + warranties; + + v. a URI or hyperlink to the Licensed Material to the + extent reasonably practicable; + + b. indicate if You modified the Licensed Material and + retain an indication of any previous modifications; and + + c. indicate the Licensed Material is licensed under this + Public License, and include the text of, or the URI or + hyperlink to, this Public License. + + 2. You may satisfy the conditions in Section 3(a)(1) in any + reasonable manner based on the medium, means, and context in + which You Share the Licensed Material. For example, it may be + reasonable to satisfy the conditions by providing a URI or + hyperlink to a resource that includes the required + information. + 3. If requested by the Licensor, You must remove any of the + information required by Section 3(a)(1)(A) to the extent + reasonably practicable. + + b. ShareAlike. + + In addition to the conditions in Section 3(a), if You Share + Adapted Material You produce, the following conditions also apply. + + 1. The Adapter's License You apply must be a Creative Commons + license with the same License Elements, this version or + later, or a BY-NC-SA Compatible License. + + 2. You must include the text of, or the URI or hyperlink to, the + Adapter's License You apply. You may satisfy this condition + in any reasonable manner based on the medium, means, and + context in which You Share Adapted Material. + + 3. You may not offer or impose any additional or different terms + or conditions on, or apply any Effective Technological + Measures to, Adapted Material that restrict exercise of the + rights granted under the Adapter's License You apply. + + +Section 4 -- Sui Generis Database Rights. + +Where the Licensed Rights include Sui Generis Database Rights that +apply to Your use of the Licensed Material: + + a. for the avoidance of doubt, Section 2(a)(1) grants You the right + to extract, reuse, reproduce, and Share all or a substantial + portion of the contents of the database for NonCommercial purposes + only; + + b. if You include all or a substantial portion of the database + contents in a database in which You have Sui Generis Database + Rights, then the database in which You have Sui Generis Database + Rights (but not its individual contents) is Adapted Material, + including for purposes of Section 3(b); and + + c. You must comply with the conditions in Section 3(a) if You Share + all or a substantial portion of the contents of the database. + +For the avoidance of doubt, this Section 4 supplements and does not +replace Your obligations under this Public License where the Licensed +Rights include other Copyright and Similar Rights. + + +Section 5 -- Disclaimer of Warranties and Limitation of Liability. + + a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE + EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS + AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF + ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, + IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, + WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR + PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, + ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT + KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT + ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. + + b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE + TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, + NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, + INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, + COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR + USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN + ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR + DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR + IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. + + c. The disclaimer of warranties and limitation of liability provided + above shall be interpreted in a manner that, to the extent + possible, most closely approximates an absolute disclaimer and + waiver of all liability. + + +Section 6 -- Term and Termination. + + a. This Public License applies for the term of the Copyright and + Similar Rights licensed here. However, if You fail to comply with + this Public License, then Your rights under this Public License + terminate automatically. + + b. Where Your right to use the Licensed Material has terminated under + Section 6(a), it reinstates: + + 1. automatically as of the date the violation is cured, provided + it is cured within 30 days of Your discovery of the + violation; or + + 2. upon express reinstatement by the Licensor. + + For the avoidance of doubt, this Section 6(b) does not affect any + right the Licensor may have to seek remedies for Your violations + of this Public License. + + c. For the avoidance of doubt, the Licensor may also offer the + Licensed Material under separate terms or conditions or stop + distributing the Licensed Material at any time; however, doing so + will not terminate this Public License. + + d. Sections 1, 5, 6, 7, and 8 survive termination of this Public + License. + + +Section 7 -- Other Terms and Conditions. + + a. The Licensor shall not be bound by any additional or different + terms or conditions communicated by You unless expressly agreed. + + b. Any arrangements, understandings, or agreements regarding the + Licensed Material not stated herein are separate from and + independent of the terms and conditions of this Public License. + + +Section 8 -- Interpretation. + + a. For the avoidance of doubt, this Public License does not, and + shall not be interpreted to, reduce, limit, restrict, or impose + conditions on any use of the Licensed Material that could lawfully + be made without permission under this Public License. + + b. To the extent possible, if any provision of this Public License is + deemed unenforceable, it shall be automatically reformed to the + minimum extent necessary to make it enforceable. If the provision + cannot be reformed, it shall be severed from this Public License + without affecting the enforceability of the remaining terms and + conditions. + + c. No term or condition of this Public License will be waived and no + failure to comply consented to unless expressly agreed to by the + Licensor. + + d. Nothing in this Public License constitutes or may be interpreted + as a limitation upon, or waiver of, any privileges and immunities + that apply to the Licensor or You, including from the legal + processes of any jurisdiction or authority. + +======================================================================= + +Creative Commons is not a party to its public +licenses. Notwithstanding, Creative Commons may elect to apply one of +its public licenses to material it publishes and in those instances +will be considered the “Licensor.” The text of the Creative Commons +public licenses is dedicated to the public domain under the CC0 Public +Domain Dedication. Except for the limited purpose of indicating that +material is shared under a Creative Commons public license or as +otherwise permitted by the Creative Commons policies published at +creativecommons.org/policies, Creative Commons does not authorize the +use of the trademark "Creative Commons" or any other trademark or logo +of Creative Commons without its prior written consent including, +without limitation, in connection with any unauthorized modifications +to any of its public licenses or any other arrangements, +understandings, or agreements concerning use of licensed material. For +the avoidance of doubt, this paragraph does not form part of the +public licenses. + +Creative Commons may be contacted at creativecommons.org. diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/resources/README.md b/data/crac-creation/crac-creator-csa-profiles/src/test/resources/README.md new file mode 100644 index 0000000000..cbe2bc592e --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/src/test/resources/README.md @@ -0,0 +1,13 @@ +# CSA/NC Test Configurations (TC) +Network Code (NC) profiles for Coordinated Security Analysis(CSA) Test Configuration (TC) + +Shield: [![CC BY-NC-SA 4.0][cc-by-nc-sa-shield]][cc-by-nc-sa] + +This work is licensed under a +[Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License][cc-by-nc-sa]. + +[![CC BY-NC-SA 4.0][cc-by-nc-sa-image]][cc-by-nc-sa] + +[cc-by-nc-sa]: http://creativecommons.org/licenses/by-nc-sa/4.0/ +[cc-by-nc-sa-image]: https://licensebuttons.net/l/by-nc-sa/4.0/88x31.png +[cc-by-nc-sa-shield]: https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg \ No newline at end of file diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/resources/TestConfiguration_TC1_v29Mar2023.zip b/data/crac-creation/crac-creator-csa-profiles/src/test/resources/TestConfiguration_TC1_v29Mar2023.zip new file mode 100644 index 0000000000..d27c9dd42a Binary files /dev/null and b/data/crac-creation/crac-creator-csa-profiles/src/test/resources/TestConfiguration_TC1_v29Mar2023.zip differ diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/resources/Test_With_Refused_Contingencies.zip b/data/crac-creation/crac-creator-csa-profiles/src/test/resources/Test_With_Refused_Contingencies.zip new file mode 100644 index 0000000000..a2ecbafbed Binary files /dev/null and b/data/crac-creation/crac-creator-csa-profiles/src/test/resources/Test_With_Refused_Contingencies.zip differ diff --git a/data/crac-creation/crac-creator-csa-profiles/src/test/resources/logback-test.xml b/data/crac-creation/crac-creator-csa-profiles/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..881ca96b55 --- /dev/null +++ b/data/crac-creation/crac-creator-csa-profiles/src/test/resources/logback-test.xml @@ -0,0 +1,13 @@ + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + \ No newline at end of file diff --git a/data/crac-creation/pom.xml b/data/crac-creation/pom.xml index 2988156475..e0f6c3dad2 100644 --- a/data/crac-creation/pom.xml +++ b/data/crac-creation/pom.xml @@ -25,7 +25,8 @@ crac-creation-util crac-creator-api crac-creator-cse - crac-creator-cim + crac-creator-cim + crac-creator-csa-profiles crac-creator-fb-constraint diff --git a/data/result-exporter/core-cne-exporter/src/main/java/com/farao_community/farao/data/core_cne_exporter/CoreCneClassCreator.java b/data/result-exporter/core-cne-exporter/src/main/java/com/farao_community/farao/data/core_cne_exporter/CoreCneClassCreator.java index c57aa6f7a3..a8ac0a4bad 100644 --- a/data/result-exporter/core-cne-exporter/src/main/java/com/farao_community/farao/data/core_cne_exporter/CoreCneClassCreator.java +++ b/data/result-exporter/core-cne-exporter/src/main/java/com/farao_community/farao/data/core_cne_exporter/CoreCneClassCreator.java @@ -8,8 +8,8 @@ package com.farao_community.farao.data.core_cne_exporter; import com.farao_community.farao.commons.FaraoException; +import com.farao_community.farao.commons.TsoEICode; import com.farao_community.farao.commons.Unit; -import com.farao_community.farao.data.cne_exporter_commons.TsoEICode; import com.farao_community.farao.data.core_cne_exporter.xsd.*; import javax.xml.datatype.DatatypeConfigurationException; @@ -20,7 +20,8 @@ import java.util.Objects; import static com.farao_community.farao.data.cne_exporter_commons.CneConstants.*; -import static com.farao_community.farao.data.cne_exporter_commons.CneUtil.*; +import static com.farao_community.farao.data.cne_exporter_commons.CneUtil.cutString; +import static com.farao_community.farao.data.cne_exporter_commons.CneUtil.limitFloatInterval; import static com.farao_community.farao.data.core_cne_exporter.CoreCneUtil.*; /** diff --git a/data/result-exporter/core-cne-exporter/src/main/java/com/farao_community/farao/data/core_cne_exporter/CoreCneRemedialActionsCreator.java b/data/result-exporter/core-cne-exporter/src/main/java/com/farao_community/farao/data/core_cne_exporter/CoreCneRemedialActionsCreator.java index 7dfeabe0d1..53a000522c 100644 --- a/data/result-exporter/core-cne-exporter/src/main/java/com/farao_community/farao/data/core_cne_exporter/CoreCneRemedialActionsCreator.java +++ b/data/result-exporter/core-cne-exporter/src/main/java/com/farao_community/farao/data/core_cne_exporter/CoreCneRemedialActionsCreator.java @@ -8,9 +8,9 @@ package com.farao_community.farao.data.core_cne_exporter; import com.farao_community.farao.commons.FaraoException; +import com.farao_community.farao.commons.TsoEICode; import com.farao_community.farao.commons.logs.FaraoLoggerProvider; import com.farao_community.farao.data.cne_exporter_commons.CneHelper; -import com.farao_community.farao.data.cne_exporter_commons.TsoEICode; import com.farao_community.farao.data.core_cne_exporter.xsd.ConstraintSeries; import com.farao_community.farao.data.core_cne_exporter.xsd.ContingencySeries; import com.farao_community.farao.data.core_cne_exporter.xsd.RemedialActionRegisteredResource; @@ -63,21 +63,22 @@ private CoreCneRemedialActionsCreator() { * Creates RA ConstraintSeries for all RAs (B56) and adds them to the list * PS: This also adds the RemedialActionSeries to the CNECs' ConstraintSeries in the list, * so it should be done after adding the CNECs' ConstraintSeries to the list + * * @return a List of ConstraintSeries */ public List generate() { List constraintSeries = new ArrayList<>(); List sortedRangeActions = cracCreationContext.getRemedialActionCreationContexts().stream() - .sorted(Comparator.comparing(RemedialActionCreationContext::getNativeId)) - .map(raCreationContext -> cneHelper.getCrac().getPstRangeAction(raCreationContext.getCreatedRAId())) - .filter(ra -> !Objects.isNull(ra)) - .collect(Collectors.toList()); + .sorted(Comparator.comparing(RemedialActionCreationContext::getNativeId)) + .map(raCreationContext -> cneHelper.getCrac().getPstRangeAction(raCreationContext.getCreatedRAId())) + .filter(ra -> !Objects.isNull(ra)) + .collect(Collectors.toList()); List sortedNetworkActions = cracCreationContext.getRemedialActionCreationContexts().stream() - .sorted(Comparator.comparing(RemedialActionCreationContext::getNativeId)) - .map(raCreationContext -> cneHelper.getCrac().getNetworkAction(raCreationContext.getCreatedRAId())) - .filter(ra -> !Objects.isNull(ra)) - .collect(Collectors.toList()); + .sorted(Comparator.comparing(RemedialActionCreationContext::getNativeId)) + .map(raCreationContext -> cneHelper.getCrac().getNetworkAction(raCreationContext.getCreatedRAId())) + .filter(ra -> !Objects.isNull(ra)) + .collect(Collectors.toList()); logMissingRangeActions(); List usedRangeActions = sortedRangeActions.stream().filter(this::isRangeActionUsedInRao).collect(Collectors.toList()); @@ -165,7 +166,7 @@ private List createPostCraRaConstraintSeries(List - usageRule.getUsageMethod(state).equals(UsageMethod.AVAILABLE) || usageRule.getUsageMethod(state).equals(UsageMethod.FORCED))) { + usageRule.getUsageMethod(state).equals(UsageMethod.AVAILABLE) || usageRule.getUsageMethod(state).equals(UsageMethod.FORCED))) { return; } // using RaoResult.isActivatedDuringState may throw an exception @@ -226,7 +227,7 @@ private String createRangeActionId(String mRid) { public void createPostOptimNetworkRemedialActionSeries(NetworkAction networkAction, OptimizationState optimizationState, State state, ConstraintSeries constraintSeriesB56) { if (networkAction.getUsageRules().stream().noneMatch(usageRule -> - usageRule.getUsageMethod(state).equals(UsageMethod.AVAILABLE) || usageRule.getUsageMethod(state).equals(UsageMethod.FORCED))) { + usageRule.getUsageMethod(state).equals(UsageMethod.AVAILABLE) || usageRule.getUsageMethod(state).equals(UsageMethod.FORCED))) { return; } // using RaoResult.isActivatedDuringState may throw an exception