Skip to content

Commit

Permalink
Factorize writing of CGMES profiles
Browse files Browse the repository at this point in the history
Signed-off-by: Romain Courtier <[email protected]>
  • Loading branch information
rcourtier committed Oct 18, 2024
1 parent 235961a commit 0aed252
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package com.powsybl.cgmes.conversion.test;

import com.powsybl.cgmes.conversion.CgmesExport;
import com.powsybl.cgmes.conversion.CgmesImportPostProcessor;
import com.powsybl.cgmes.conversion.Conversion;
import com.powsybl.cgmes.model.CgmesModel;
Expand Down Expand Up @@ -97,6 +98,16 @@ public static Network readCgmesResources(Properties properties, String dir, Stri
return Network.read(ds, properties);
}

public static String writeCgmesProfile(Network network, String profile, Path outDir) throws IOException {
return writeCgmesProfile(network, profile, outDir, new Properties());
}

public static String writeCgmesProfile(Network network, String profile, Path outDir, Properties properties) throws IOException {
properties.put(CgmesExport.PROFILES, List.of(profile));
network.write("CGMES", properties, outDir.resolve("CgmesExport"));
return Files.readString(outDir.resolve("CgmesExport_" + profile + ".xml"));
}

public static String getFirstMatch(String text, Pattern pattern) {
Matcher matcher = pattern.matcher(text);
if (matcher.find()) {
Expand Down

0 comments on commit 0aed252

Please sign in to comment.