diff --git a/pom.xml b/pom.xml
index feac3f8..0597ad9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,10 +26,10 @@
UTF-8
0.0.2
- 2.11.0
+ 2.12.0
1.16.2
- 1.13.0
+ 1.16.0
@@ -64,26 +64,6 @@
-
-
-
- com.powsybl
- powsybl-network-store-iidm-impl
- ${powsybl-network-store.version}
-
-
-
- com.powsybl
- powsybl-network-store-client
- ${powsybl-network-store.version}
-
-
-
- com.powsybl
- powsybl-network-store-model
- ${powsybl-network-store.version}
-
-
com.powsybl
@@ -125,9 +105,24 @@
com.powsybl
powsybl-case-datasource-client
+
+
+
+ com.powsybl
+ powsybl-network-store-iidm-impl
+ ${powsybl-network-store.version}
+
+
com.powsybl
powsybl-network-store-client
+ ${powsybl-network-store.version}
+
+
+
+ com.powsybl
+ powsybl-network-store-model
+ ${powsybl-network-store.version}
com.powsybl
diff --git a/src/main/java/com/powsybl/network/conversion/server/NetworkConversionController.java b/src/main/java/com/powsybl/network/conversion/server/NetworkConversionController.java
index e6146f6..980ac31 100644
--- a/src/main/java/com/powsybl/network/conversion/server/NetworkConversionController.java
+++ b/src/main/java/com/powsybl/network/conversion/server/NetworkConversionController.java
@@ -83,10 +83,11 @@ public ResponseEntity importCase(@Parameter(description = "Case UU
public ResponseEntity exportNetwork(@Parameter(description = "Network UUID") @PathVariable("mainNetworkUuid") UUID networkUuid,
@Parameter(description = "Export format")@PathVariable("format") String format,
@Parameter(description = "Variant Id") @RequestParam(name = "variantId", required = false) String variantId,
+ @Parameter(description = "File name") @RequestParam(name = "fileName", required = false) String fileName,
@org.springframework.web.bind.annotation.RequestBody(required = false) Map formatParameters
) throws IOException {
LOGGER.debug("Exporting network {}...", networkUuid);
- ExportNetworkInfos exportNetworkInfos = networkConversionObserver.observeExport(format, () -> networkConversionService.exportNetwork(networkUuid, variantId, format, formatParameters));
+ ExportNetworkInfos exportNetworkInfos = networkConversionObserver.observeExport(format, () -> networkConversionService.exportNetwork(networkUuid, variantId, fileName, format, formatParameters));
HttpHeaders header = new HttpHeaders();
header.setContentDisposition(ContentDisposition.builder("attachment").filename(exportNetworkInfos.getNetworkName(), StandardCharsets.UTF_8).build());
return ResponseEntity.ok().headers(header).contentType(MediaType.APPLICATION_OCTET_STREAM).body(exportNetworkInfos.getNetworkData());
diff --git a/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java b/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java
index 70c0c64..438dd4f 100644
--- a/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java
+++ b/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java
@@ -13,9 +13,6 @@
import com.powsybl.cases.datasource.CaseDataSourceClient;
import com.powsybl.cgmes.conversion.export.CgmesExportContext;
import com.powsybl.cgmes.conversion.export.StateVariablesExport;
-import com.powsybl.cgmes.extensions.CgmesMetadataModels;
-import com.powsybl.cgmes.model.CgmesMetadataModel;
-import com.powsybl.cgmes.model.CgmesSubset;
import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.datasource.MemDataSource;
import com.powsybl.commons.parameters.ParameterScope;
@@ -287,7 +284,7 @@ private Network getNetwork(UUID networkUuid) {
}
}
- ExportNetworkInfos exportNetwork(UUID networkUuid, String variantId,
+ ExportNetworkInfos exportNetwork(UUID networkUuid, String variantId, String fileName,
String format, Map formatParameters) throws IOException {
if (!Exporter.getFormats().contains(format)) {
throw NetworkConversionException.createFormatUnsupported(format);
@@ -311,19 +308,24 @@ ExportNetworkInfos exportNetwork(UUID networkUuid, String variantId,
network.write(format, exportProperties, memDataSource);
Set listNames = memDataSource.listNames(".*");
- String networkName;
+ String fileOrNetworkName = fileName != null ? fileName : getNetworkName(network, variantId);
byte[] networkData;
- networkName = network.getNameOrId();
- networkName += "_" + (variantId == null ? VariantManagerConstants.INITIAL_VARIANT_ID : variantId);
+
if (listNames.size() == 1) {
- networkName += listNames.toArray()[0];
+ fileOrNetworkName += listNames.toArray()[0];
networkData = memDataSource.getData(listNames.toArray()[0].toString());
} else {
- networkName += ".zip";
+ fileOrNetworkName += ".zip";
networkData = createZipFile(listNames.toArray(new String[0]), memDataSource).toByteArray();
}
long networkSize = network.getBusView().getBusStream().count();
- return new ExportNetworkInfos(networkName, networkData, networkSize);
+ return new ExportNetworkInfos(fileOrNetworkName, networkData, networkSize);
+ }
+
+ private String getNetworkName(Network network, String variantId) {
+ String networkName = network.getNameOrId();
+ networkName += "_" + (variantId == null ? VariantManagerConstants.INITIAL_VARIANT_ID : variantId);
+ return networkName;
}
ByteArrayOutputStream createZipFile(String[] listNames, MemDataSource dataSource) throws IOException {
@@ -402,14 +404,6 @@ public ExportNetworkInfos exportCgmesSv(UUID networkUuid) throws XMLStreamExcept
private static CgmesExportContext createContext(Network network) {
CgmesExportContext context = new CgmesExportContext();
context.setScenarioTime(network.getCaseDate());
- Optional cgmesMetadataModelOpt = network.getExtension(CgmesMetadataModels.class).getModelForSubset(CgmesSubset.STATE_VARIABLES);
- if (cgmesMetadataModelOpt.isPresent()) {
- context.getExportedSVModel().addDependentOn(cgmesMetadataModelOpt.get().getId());
- }
- cgmesMetadataModelOpt = network.getExtension(CgmesMetadataModels.class).getModelForSubset(CgmesSubset.STEADY_STATE_HYPOTHESIS);
- if (cgmesMetadataModelOpt.isPresent()) {
- context.getExportedSSHModel().addDependentOn(cgmesMetadataModelOpt.get().getId());
- }
context.addIidmMappings(network);
return context;
}
diff --git a/src/test/java/com/powsybl/network/conversion/server/NetworkConversionTest.java b/src/test/java/com/powsybl/network/conversion/server/NetworkConversionTest.java
index ee0f6b2..3b38276 100644
--- a/src/test/java/com/powsybl/network/conversion/server/NetworkConversionTest.java
+++ b/src/test/java/com/powsybl/network/conversion/server/NetworkConversionTest.java
@@ -130,7 +130,7 @@ public void test() throws Exception {
any(HttpEntity.class),
eq(String.class), eq(UUID.fromString(caseUuid))))
.willReturn(ResponseEntity.ok("testCase"));
- given(caseServerRest.getForEntity(eq("/v1/cases/" + caseUuid + "/infos"), any())).willReturn(ResponseEntity.ok(new CaseInfos(UUID.fromString(caseUuid.toString()), "testCase", "XIIDM")));
+ given(caseServerRest.getForEntity(eq("/v1/cases/" + caseUuid + "/infos"), any())).willReturn(ResponseEntity.ok(new CaseInfos(UUID.fromString(caseUuid.toString()), "testCase.xiidm", "XIIDM")));
MvcResult mvcResult = mvc.perform(post("/v1/networks")
.param("caseUuid", caseUuid)
@@ -177,7 +177,6 @@ public void test() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_OCTET_STREAM))
.andReturn();
-
assertTrue(Objects.requireNonNull(mvcResult.getResponse().getHeader("content-disposition")).contains("attachment;"));
assertTrue(Objects.requireNonNull(mvcResult.getResponse().getHeader("content-disposition")).contains(String.format("filename*=UTF-8''20140116_0830_2D4_UX1_pst_%s.xiidm", VariantManagerConstants.INITIAL_VARIANT_ID)));
assertTrue(mvcResult.getResponse().getContentAsString().startsWith(""));
@@ -203,6 +202,16 @@ public void test() throws Exception {
// takes the iidm.export.xml.indent param into account
assertTrue(exported1.length() > exported2.length());
+ //with fileName
+ mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}?fileName=" + "studyName_Root", UUID.randomUUID().toString(), "XIIDM").param("variantId", "second_variant_id"))
+ .andExpect(status().isOk())
+ .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_OCTET_STREAM))
+ .andReturn();
+
+ assertTrue(Objects.requireNonNull(mvcResult.getResponse().getHeader("content-disposition")).contains("attachment;"));
+ assertTrue(Objects.requireNonNull(mvcResult.getResponse().getHeader("content-disposition")).contains("filename*=UTF-8''studyName_Root.xiidm"));
+ assertTrue(mvcResult.getResponse().getContentAsString().startsWith(""));
+
// non existing variantId
mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}", UUID.randomUUID().toString(), "XIIDM").param("variantId", "unknown_variant_id"))
.andExpect(status().isNotFound())
@@ -365,12 +374,13 @@ public void testExportSv() throws Exception {
assertTrue(Objects.requireNonNull(mvcResult.getResponse().getHeader("content-disposition")).contains("attachment;"));
assertTrue(Objects.requireNonNull(mvcResult.getResponse().getHeader("content-disposition")).contains("filename*=UTF-8''urn%3Auuid%3Ad400c631-75a0-4c30-8aed-832b0d282e73"));
- assertTrue(mvcResult.getResponse().getContentAsString().contains("SV Model\n" +
- " 1\n" +
- " \n" +
- " http://entsoe.eu/CIM/StateVariables/4/1\n" +
- " powsybl.org\n" +
- " "));
+ assertTrue(mvcResult.getResponse().getContentAsString().contains("CGMES Conformity Assessment: 'MicroGridTestConfiguration....BC (MAS BE) Test Configuration. The model is owned by ENTSO-E and is provided by ENTSO-E â\u0080\u009Cas it isâ\u0080\u009D. 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 model (including any of its subsequent modifications). ENTSO-E neither warrants, nor represents that the use of the model will not infringe the rights of third parties. Any use of the model shall include a reference to ENTSO-E. ENTSO-E web site is the only official source of information related to the model.\n" +
+ " 2\n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " http://entsoe.eu/CIM/StateVariables/4/1\n" +
+ " http://elia.be/CGMES/2.4.15"));
}
@Test