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

[CGMES] Add new parameter to make ModelDescription custom #2628

Merged
merged 8 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -80,6 +80,13 @@ public void export(Network network, Properties params, DataSource ds, Reporter r
context.getTpModelDescription().setModelingAuthoritySet(Parameter.readString(getFormat(), params, MODELING_AUTHORITY_SET_PARAMETER, defaultValueConfig));
context.getSshModelDescription().setModelingAuthoritySet(Parameter.readString(getFormat(), params, MODELING_AUTHORITY_SET_PARAMETER, defaultValueConfig));
context.getSvModelDescription().setModelingAuthoritySet(Parameter.readString(getFormat(), params, MODELING_AUTHORITY_SET_PARAMETER, defaultValueConfig));
String modelDescription = Parameter.readString(getFormat(), params, MODEL_DESCRIPTION_PARAMETER, defaultValueConfig);
if (modelDescription != null) {
context.getEqModelDescription().setDescription(modelDescription);
context.getTpModelDescription().setDescription(modelDescription);
context.getSshModelDescription().setDescription(modelDescription);
context.getSvModelDescription().setDescription(modelDescription);
}
String cimVersionParam = Parameter.readString(getFormat(), params, CIM_VERSION_PARAMETER, defaultValueConfig);
if (cimVersionParam != null) {
context.setCimVersion(Integer.parseInt(cimVersionParam));
Expand Down Expand Up @@ -182,6 +189,7 @@ public String getFormat() {
public static final String NAMING_STRATEGY = "iidm.export.cgmes.naming-strategy";
public static final String PROFILES = "iidm.export.cgmes.profiles";
public static final String MODELING_AUTHORITY_SET = "iidm.export.cgmes.modeling-authority-set";
public static final String MODEL_DESCRIPTION = "iidm.export.cgmes.model-description";

private static final Parameter BASE_NAME_PARAMETER = new Parameter(
BASE_NAME,
Expand Down Expand Up @@ -238,6 +246,12 @@ public String getFormat() {
"Modeling authority set",
"powsybl.org");

private static final Parameter MODEL_DESCRIPTION_PARAMETER = new Parameter(
MODEL_DESCRIPTION,
ParameterType.STRING,
"Model description",
null);

private static final List<Parameter> STATIC_PARAMETERS = List.of(
colinepiloquet marked this conversation as resolved.
Show resolved Hide resolved
BASE_NAME_PARAMETER,
CIM_VERSION_PARAMETER,
Expand All @@ -247,7 +261,8 @@ public String getFormat() {
PROFILES_PARAMETER,
BOUNDARY_EQ_ID_PARAMETER,
BOUNDARY_TP_ID_PARAMETER,
MODELING_AUTHORITY_SET_PARAMETER);
MODELING_AUTHORITY_SET_PARAMETER,
MODEL_DESCRIPTION_PARAMETER);

private static final Logger LOG = LoggerFactory.getLogger(CgmesExport.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CgmesExportContextTest {
void testExporter() {
var exporter = new CgmesExport();
assertEquals("ENTSO-E CGMES version 2.4.15", exporter.getComment());
assertEquals(9, exporter.getParameters().size());
assertEquals(10, exporter.getParameters().size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.powsybl.cgmes.conversion.CgmesExport;
import com.powsybl.cgmes.conversion.Conversion;
import com.powsybl.cgmes.conversion.export.CgmesExportUtil;
import com.powsybl.cgmes.extensions.CgmesSshMetadata;
import com.powsybl.cgmes.model.CgmesModel;
import com.powsybl.cgmes.model.CgmesModelFactory;
import com.powsybl.cgmes.model.CgmesNames;
Expand All @@ -22,11 +23,15 @@
import com.powsybl.commons.datasource.GenericReadOnlyDataSource;
import com.powsybl.commons.datasource.ReadOnlyDataSource;
import com.powsybl.commons.datasource.ResourceSet;
import com.powsybl.commons.datasource.ZipFileDataSource;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.test.BatteryNetworkFactory;
import com.powsybl.iidm.network.test.DanglingLineNetworkFactory;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.network.test.FictitiousSwitchFactory;
import com.powsybl.iidm.network.util.Networks;
import com.powsybl.iidm.xml.ExportOptions;
import com.powsybl.iidm.xml.NetworkXml;
import com.powsybl.triplestore.api.TripleStoreFactory;
import org.junit.jupiter.api.Test;

Expand All @@ -37,9 +42,11 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.*;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

import static com.powsybl.cgmes.conversion.test.export.ExportXmlCompare.compareEQNetworks;
import static org.junit.jupiter.api.Assertions.*;

/**
Expand Down Expand Up @@ -457,6 +464,44 @@ void testLineContainersNotInBoundaries() throws IOException {
}
}

@Test
void testModelDescription() throws IOException {
Network network = EurostagTutorialExample1Factory.create();

String modelDescription = "powsybl community";
Properties params = new Properties();
params.put(CgmesExport.MODEL_DESCRIPTION, modelDescription);

FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix());
colinepiloquet marked this conversation as resolved.
Show resolved Hide resolved
Path tmpDir = Files.createDirectory(fileSystem.getPath("tmp"));
ZipFileDataSource zip = new ZipFileDataSource(tmpDir.resolve("."), "output");
new CgmesExport().export(network, params, zip);
Network network2 = Network.read(tmpDir.resolve("output.zip"));
CgmesSshMetadata sshMetadata = network2.getExtension(CgmesSshMetadata.class);
assertEquals(modelDescription, sshMetadata.getDescription());
}

@Test
void testModelDescriptionClosingXML() throws IOException {
Network network = EurostagTutorialExample1Factory.create();

// Security test
// Checking that putting end-tag does not corrupt the file
String modelDescription = "powsybl community</md:Model.modelingAuthoritySet></md:FullModel>";
Properties params = new Properties();
params.put(CgmesExport.MODEL_DESCRIPTION, modelDescription);

FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix());
colinepiloquet marked this conversation as resolved.
Show resolved Hide resolved
Path tmpDir = Files.createDirectory(fileSystem.getPath("tmp"));
ZipFileDataSource zip = new ZipFileDataSource(tmpDir.resolve("."), "output");
new CgmesExport().export(network, params, zip);

// check network can be reimported and that ModelDescription still includes end-tag
Network network2 = Network.read(tmpDir.resolve("output.zip"));
CgmesSshMetadata sshMetadata = network2.getExtension(CgmesSshMetadata.class);
assertEquals(modelDescription, sshMetadata.getDescription());
}

private static void checkDanglingLineParams(DanglingLine expected, DanglingLine actual) {
assertEquals(expected.getR(), actual.getR(), EPSILON);
assertEquals(expected.getX(), actual.getX(), EPSILON);
Expand Down