From 346987e4638d33444b9529f07884d9893e0816a1 Mon Sep 17 00:00:00 2001 From: maissa SOUISSI Date: Tue, 18 Jun 2024 17:40:56 +0200 Subject: [PATCH 01/11] change name file when exporting study Signed-off-by: maissa SOUISSI --- .../server/NetworkConversionController.java | 5 ++++- .../server/NetworkConversionService.java | 17 ++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) 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..799a2c4 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,13 @@ 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 = "Case Uuid") @RequestParam(name = "caseUuid", required = false) UUID caseUuid, + @Parameter(description = "Node name") @RequestParam(name = "nodeName") String nodeName, + @Parameter(description = "Study name") @RequestParam(name = "studyName", required = false) String studyName, @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, caseUuid, nodeName, studyName, 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..1dc9e1a 100644 --- a/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java +++ b/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java @@ -287,7 +287,7 @@ private Network getNetwork(UUID networkUuid) { } } - ExportNetworkInfos exportNetwork(UUID networkUuid, String variantId, + ExportNetworkInfos exportNetwork(UUID networkUuid, String variantId, UUID caseUuid, String nodeName, String studyName, String format, Map formatParameters) throws IOException { if (!Exporter.getFormats().contains(format)) { throw NetworkConversionException.createFormatUnsupported(format); @@ -311,19 +311,22 @@ ExportNetworkInfos exportNetwork(UUID networkUuid, String variantId, network.write(format, exportProperties, memDataSource); Set listNames = memDataSource.listNames(".*"); - String networkName; byte[] networkData; - networkName = network.getNameOrId(); - networkName += "_" + (variantId == null ? VariantManagerConstants.INITIAL_VARIANT_ID : variantId); + String caseName = null; + if (studyName == null) { + String caseNameWithFormat = getCaseInfos(caseUuid).getName(); + caseName = caseNameWithFormat.substring(0, caseNameWithFormat.lastIndexOf(".")); + + } + + String fileName = studyName == null ? caseName : studyName + "_" + nodeName; if (listNames.size() == 1) { - networkName += listNames.toArray()[0]; networkData = memDataSource.getData(listNames.toArray()[0].toString()); } else { - networkName += ".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(fileName, networkData, networkSize); } ByteArrayOutputStream createZipFile(String[] listNames, MemDataSource dataSource) throws IOException { From dc670958908079f9036a486047b1850d9d8d9979 Mon Sep 17 00:00:00 2001 From: maissa SOUISSI Date: Thu, 20 Jun 2024 01:54:48 +0200 Subject: [PATCH 02/11] fix tu Signed-off-by: maissa SOUISSI --- .../server/NetworkConversionService.java | 4 +++- .../server/NetworkConversionTest.java | 17 ++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) 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 1dc9e1a..4b2fbd7 100644 --- a/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java +++ b/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java @@ -319,10 +319,12 @@ ExportNetworkInfos exportNetwork(UUID networkUuid, String variantId, UUID caseUu } - String fileName = studyName == null ? caseName : studyName + "_" + nodeName; + String fileName = studyName == null ? caseName + "_" + nodeName : studyName + "_" + nodeName; if (listNames.size() == 1) { + fileName += listNames.toArray()[0]; networkData = memDataSource.getData(listNames.toArray()[0].toString()); } else { + fileName += ".zip"; networkData = createZipFile(listNames.toArray(new String[0]), memDataSource).toByteArray(); } long networkSize = network.getBusView().getBusStream().count(); 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..d3bf824 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) @@ -173,22 +173,21 @@ public void test() throws Exception { UUID notFoundNetworkUuid = UUID.randomUUID(); given(networkStoreClient.getNetwork(notFoundNetworkUuid)).willThrow(new PowsyblException("Network " + notFoundNetworkUuid.toString() + " not found")); given(networkStoreClient.getNetwork(any(UUID.class), eq(PreloadingStrategy.COLLECTION))).willReturn(network); - mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}", UUID.randomUUID().toString(), "XIIDM")) + mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}?caseUuid=" + caseUuid + "&nodeName=Root", UUID.randomUUID().toString(), "XIIDM")) .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(Objects.requireNonNull(mvcResult.getResponse().getHeader("content-disposition")).contains(String.format("filename*=UTF-8''%s_%s.xiidm", "testCase", "Root"))); assertTrue(mvcResult.getResponse().getContentAsString().startsWith("")); - mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}", UUID.randomUUID().toString(), "XIIDM").param("variantId", "second_variant_id")) + mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}?caseUuid=" + caseUuid + "&nodeName=Root", UUID.randomUUID().toString(), "XIIDM").param("variantId", "second_variant_id")) .andExpect(status().isOk()) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_OCTET_STREAM)) .andReturn(); String exported1 = mvcResult.getResponse().getContentAsString(); - mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}", UUID.randomUUID().toString(), "XIIDM").param("variantId", "second_variant_id") + mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}?caseUuid=" + caseUuid + "&nodeName=Root", UUID.randomUUID().toString(), "XIIDM").param("variantId", "second_variant_id") .contentType("application/json") .content("{ \"iidm.export.xml.indent\" : \"false\"}")) .andExpect(status().isOk()) @@ -197,19 +196,19 @@ public void test() throws Exception { String exported2 = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); assertTrue(Objects.requireNonNull(mvcResult.getResponse().getHeader("content-disposition")).contains("attachment;")); - assertTrue(Objects.requireNonNull(mvcResult.getResponse().getHeader("content-disposition")).contains("filename*=UTF-8''20140116_0830_2D4_UX1_pst_second_variant_id.xiidm")); + assertTrue(Objects.requireNonNull(mvcResult.getResponse().getHeader("content-disposition")).contains("filename*=UTF-8''testCase_Root.xiidm")); assertTrue(mvcResult.getResponse().getContentAsString().startsWith("")); // takes the iidm.export.xml.indent param into account assertTrue(exported1.length() > exported2.length()); // non existing variantId - mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}", UUID.randomUUID().toString(), "XIIDM").param("variantId", "unknown_variant_id")) + mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}?caseUuid=" + caseUuid + "&nodeName=Root", UUID.randomUUID().toString(), "XIIDM").param("variantId", "unknown_variant_id")) .andExpect(status().isNotFound()) .andReturn(); // non existing format - mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}", UUID.randomUUID().toString(), "JPEG").param("variantId", "second_variant_id")) + mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}?caseUuid=" + caseUuid + "&nodeName=Root\"", UUID.randomUUID().toString(), "JPEG").param("variantId", "second_variant_id")) .andExpect(status().isInternalServerError()) .andReturn(); From 96a1fc4ec6065c079c588825e18334ea7bdada6d Mon Sep 17 00:00:00 2001 From: maissa SOUISSI Date: Thu, 20 Jun 2024 20:42:56 +0200 Subject: [PATCH 03/11] tu Signed-off-by: maissa SOUISSI --- .../conversion/server/NetworkConversionTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 d3bf824..abda3d6 100644 --- a/src/test/java/com/powsybl/network/conversion/server/NetworkConversionTest.java +++ b/src/test/java/com/powsybl/network/conversion/server/NetworkConversionTest.java @@ -202,6 +202,16 @@ public void test() throws Exception { // takes the iidm.export.xml.indent param into account assertTrue(exported1.length() > exported2.length()); + //with studyName, filename should + mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}?studyName=" + "studyName" + "&nodeName=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}?caseUuid=" + caseUuid + "&nodeName=Root", UUID.randomUUID().toString(), "XIIDM").param("variantId", "unknown_variant_id")) .andExpect(status().isNotFound()) From feaac5439871a200d2926d103d16c73e9140a53c Mon Sep 17 00:00:00 2001 From: maissa SOUISSI Date: Tue, 2 Jul 2024 02:40:40 +0200 Subject: [PATCH 04/11] fix : provide filename if needed Signed-off-by: maissa SOUISSI --- .../server/NetworkConversionController.java | 6 ++--- .../server/NetworkConversionService.java | 25 +++++++++++-------- .../server/NetworkConversionTest.java | 18 ++++++------- 3 files changed, 25 insertions(+), 24 deletions(-) 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 799a2c4..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,13 +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 = "Case Uuid") @RequestParam(name = "caseUuid", required = false) UUID caseUuid, - @Parameter(description = "Node name") @RequestParam(name = "nodeName") String nodeName, - @Parameter(description = "Study name") @RequestParam(name = "studyName", required = false) String studyName, + @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, caseUuid, nodeName, studyName, 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 4b2fbd7..5ec9703 100644 --- a/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java +++ b/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java @@ -287,7 +287,7 @@ private Network getNetwork(UUID networkUuid) { } } - ExportNetworkInfos exportNetwork(UUID networkUuid, String variantId, UUID caseUuid, String nodeName, String studyName, + ExportNetworkInfos exportNetwork(UUID networkUuid, String variantId, String fileName, String format, Map formatParameters) throws IOException { if (!Exporter.getFormats().contains(format)) { throw NetworkConversionException.createFormatUnsupported(format); @@ -311,24 +311,27 @@ ExportNetworkInfos exportNetwork(UUID networkUuid, String variantId, UUID caseUu network.write(format, exportProperties, memDataSource); Set listNames = memDataSource.listNames(".*"); + String fileOrNetworkName = getFileOrNetworkName(network, variantId, fileName); byte[] networkData; - String caseName = null; - if (studyName == null) { - String caseNameWithFormat = getCaseInfos(caseUuid).getName(); - caseName = caseNameWithFormat.substring(0, caseNameWithFormat.lastIndexOf(".")); - } - - String fileName = studyName == null ? caseName + "_" + nodeName : studyName + "_" + nodeName; if (listNames.size() == 1) { - fileName += listNames.toArray()[0]; + fileOrNetworkName += listNames.toArray()[0]; networkData = memDataSource.getData(listNames.toArray()[0].toString()); } else { - fileName += ".zip"; + fileOrNetworkName += ".zip"; networkData = createZipFile(listNames.toArray(new String[0]), memDataSource).toByteArray(); } long networkSize = network.getBusView().getBusStream().count(); - return new ExportNetworkInfos(fileName, networkData, networkSize); + return new ExportNetworkInfos(fileOrNetworkName, networkData, networkSize); + } + + private String getFileOrNetworkName(Network network, String variantId, String fileName) { + if (fileName == null) { + String networkName = network.getNameOrId(); + networkName += "_" + (variantId == null ? VariantManagerConstants.INITIAL_VARIANT_ID : variantId); + return networkName; + } + return fileName; } ByteArrayOutputStream createZipFile(String[] listNames, MemDataSource dataSource) throws IOException { 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 abda3d6..19d7eca 100644 --- a/src/test/java/com/powsybl/network/conversion/server/NetworkConversionTest.java +++ b/src/test/java/com/powsybl/network/conversion/server/NetworkConversionTest.java @@ -173,21 +173,21 @@ public void test() throws Exception { UUID notFoundNetworkUuid = UUID.randomUUID(); given(networkStoreClient.getNetwork(notFoundNetworkUuid)).willThrow(new PowsyblException("Network " + notFoundNetworkUuid.toString() + " not found")); given(networkStoreClient.getNetwork(any(UUID.class), eq(PreloadingStrategy.COLLECTION))).willReturn(network); - mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}?caseUuid=" + caseUuid + "&nodeName=Root", UUID.randomUUID().toString(), "XIIDM")) + mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}", UUID.randomUUID().toString(), "XIIDM")) .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''%s_%s.xiidm", "testCase", "Root"))); + 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("")); - mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}?caseUuid=" + caseUuid + "&nodeName=Root", UUID.randomUUID().toString(), "XIIDM").param("variantId", "second_variant_id")) + mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}", UUID.randomUUID().toString(), "XIIDM").param("variantId", "second_variant_id")) .andExpect(status().isOk()) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_OCTET_STREAM)) .andReturn(); String exported1 = mvcResult.getResponse().getContentAsString(); - mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}?caseUuid=" + caseUuid + "&nodeName=Root", UUID.randomUUID().toString(), "XIIDM").param("variantId", "second_variant_id") + mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}", UUID.randomUUID().toString(), "XIIDM").param("variantId", "second_variant_id") .contentType("application/json") .content("{ \"iidm.export.xml.indent\" : \"false\"}")) .andExpect(status().isOk()) @@ -196,14 +196,14 @@ public void test() throws Exception { String exported2 = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); assertTrue(Objects.requireNonNull(mvcResult.getResponse().getHeader("content-disposition")).contains("attachment;")); - assertTrue(Objects.requireNonNull(mvcResult.getResponse().getHeader("content-disposition")).contains("filename*=UTF-8''testCase_Root.xiidm")); + assertTrue(Objects.requireNonNull(mvcResult.getResponse().getHeader("content-disposition")).contains("filename*=UTF-8''20140116_0830_2D4_UX1_pst_second_variant_id.xiidm")); assertTrue(mvcResult.getResponse().getContentAsString().startsWith("")); // takes the iidm.export.xml.indent param into account assertTrue(exported1.length() > exported2.length()); - //with studyName, filename should - mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}?studyName=" + "studyName" + "&nodeName=Root", UUID.randomUUID().toString(), "XIIDM").param("variantId", "second_variant_id")) + //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(); @@ -213,12 +213,12 @@ public void test() throws Exception { assertTrue(mvcResult.getResponse().getContentAsString().startsWith("")); // non existing variantId - mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}?caseUuid=" + caseUuid + "&nodeName=Root", UUID.randomUUID().toString(), "XIIDM").param("variantId", "unknown_variant_id")) + mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}", UUID.randomUUID().toString(), "XIIDM").param("variantId", "unknown_variant_id")) .andExpect(status().isNotFound()) .andReturn(); // non existing format - mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}?caseUuid=" + caseUuid + "&nodeName=Root\"", UUID.randomUUID().toString(), "JPEG").param("variantId", "second_variant_id")) + mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/export/{format}", UUID.randomUUID().toString(), "JPEG").param("variantId", "second_variant_id")) .andExpect(status().isInternalServerError()) .andReturn(); From 6a9fe85464272c420807c0559ba3b8d7729016e4 Mon Sep 17 00:00:00 2001 From: maissa SOUISSI Date: Mon, 8 Jul 2024 17:04:45 +0200 Subject: [PATCH 05/11] refactoring .. Signed-off-by: maissa SOUISSI --- .../server/NetworkConversionController.java | 2 +- .../server/NetworkConversionService.java | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) 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 980ac31..bb957f0 100644 --- a/src/main/java/com/powsybl/network/conversion/server/NetworkConversionController.java +++ b/src/main/java/com/powsybl/network/conversion/server/NetworkConversionController.java @@ -113,7 +113,7 @@ public ResponseEntity getCaseImportParameters(@Parameter @Operation(summary = "Export a cgmes network from the network-store") public ResponseEntity exportCgmesSv(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid) throws XMLStreamException { LOGGER.debug("Exporting network {}...", networkUuid); - ExportNetworkInfos exportNetworkInfos = networkConversionObserver.observeExport("CGMES", () -> networkConversionService.exportCgmesSv(networkUuid)); + ExportNetworkInfos exportNetworkInfos = networkConversionObserver.observeExport("CGMES", () -> networkConversionService.exportCgmesSv(networkUuid, "???")); 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 5ec9703..07f2986 100644 --- a/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java +++ b/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java @@ -311,7 +311,7 @@ ExportNetworkInfos exportNetwork(UUID networkUuid, String variantId, String file network.write(format, exportProperties, memDataSource); Set listNames = memDataSource.listNames(".*"); - String fileOrNetworkName = getFileOrNetworkName(network, variantId, fileName); + String fileOrNetworkName = fileName != null ? fileName : getNetworkName(network, variantId); byte[] networkData; if (listNames.size() == 1) { @@ -325,13 +325,10 @@ ExportNetworkInfos exportNetwork(UUID networkUuid, String variantId, String file return new ExportNetworkInfos(fileOrNetworkName, networkData, networkSize); } - private String getFileOrNetworkName(Network network, String variantId, String fileName) { - if (fileName == null) { - String networkName = network.getNameOrId(); - networkName += "_" + (variantId == null ? VariantManagerConstants.INITIAL_VARIANT_ID : variantId); - return networkName; - } - return fileName; + 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 { @@ -386,7 +383,7 @@ void setGeoDataServerRest(RestTemplate geoDataServerRest) { this.geoDataServerRest = Objects.requireNonNull(geoDataServerRest, "geoDataServerRest can't be null"); } - public ExportNetworkInfos exportCgmesSv(UUID networkUuid) throws XMLStreamException { + public ExportNetworkInfos exportCgmesSv(UUID networkUuid, String fileName) throws XMLStreamException { Network network = getNetwork(networkUuid); Properties properties = new Properties(); @@ -404,7 +401,7 @@ public ExportNetworkInfos exportCgmesSv(UUID networkUuid) throws XMLStreamExcept } } long networkSize = network.getBusView().getBusStream().count(); - return new ExportNetworkInfos(network.getNameOrId(), outputStream.toByteArray(), networkSize); + return new ExportNetworkInfos(fileName != null ? fileName : network.getNameOrId(), outputStream.toByteArray(), networkSize); } private static CgmesExportContext createContext(Network network) { From 8088b7dd68e22e2ca9f1868d1e2c6f7d9d158ad4 Mon Sep 17 00:00:00 2001 From: maissa SOUISSI Date: Mon, 8 Jul 2024 17:53:51 +0200 Subject: [PATCH 06/11] fix Signed-off-by: maissa SOUISSI --- .../conversion/server/NetworkConversionController.java | 2 +- .../network/conversion/server/NetworkConversionService.java | 4 ++-- .../network/conversion/server/NetworkConversionTest.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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 bb957f0..980ac31 100644 --- a/src/main/java/com/powsybl/network/conversion/server/NetworkConversionController.java +++ b/src/main/java/com/powsybl/network/conversion/server/NetworkConversionController.java @@ -113,7 +113,7 @@ public ResponseEntity getCaseImportParameters(@Parameter @Operation(summary = "Export a cgmes network from the network-store") public ResponseEntity exportCgmesSv(@Parameter(description = "Network UUID") @PathVariable("networkUuid") UUID networkUuid) throws XMLStreamException { LOGGER.debug("Exporting network {}...", networkUuid); - ExportNetworkInfos exportNetworkInfos = networkConversionObserver.observeExport("CGMES", () -> networkConversionService.exportCgmesSv(networkUuid, "???")); + ExportNetworkInfos exportNetworkInfos = networkConversionObserver.observeExport("CGMES", () -> networkConversionService.exportCgmesSv(networkUuid)); 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 07f2986..1767bca 100644 --- a/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java +++ b/src/main/java/com/powsybl/network/conversion/server/NetworkConversionService.java @@ -383,7 +383,7 @@ void setGeoDataServerRest(RestTemplate geoDataServerRest) { this.geoDataServerRest = Objects.requireNonNull(geoDataServerRest, "geoDataServerRest can't be null"); } - public ExportNetworkInfos exportCgmesSv(UUID networkUuid, String fileName) throws XMLStreamException { + public ExportNetworkInfos exportCgmesSv(UUID networkUuid) throws XMLStreamException { Network network = getNetwork(networkUuid); Properties properties = new Properties(); @@ -401,7 +401,7 @@ public ExportNetworkInfos exportCgmesSv(UUID networkUuid, String fileName) throw } } long networkSize = network.getBusView().getBusStream().count(); - return new ExportNetworkInfos(fileName != null ? fileName : network.getNameOrId(), outputStream.toByteArray(), networkSize); + return new ExportNetworkInfos(network.getNameOrId(), outputStream.toByteArray(), networkSize); } private static CgmesExportContext createContext(Network network) { 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 19d7eca..9104a20 100644 --- a/src/test/java/com/powsybl/network/conversion/server/NetworkConversionTest.java +++ b/src/test/java/com/powsybl/network/conversion/server/NetworkConversionTest.java @@ -373,7 +373,7 @@ public void testExportSv() throws Exception { .andReturn(); 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(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" + From 7d7387cef07c6053cc10fa8a375d39ae3c2a4c3b Mon Sep 17 00:00:00 2001 From: FranckLecuyer <47824306+FranckLecuyer@users.noreply.github.com> Date: Mon, 29 Jul 2024 12:00:09 +0200 Subject: [PATCH 07/11] Upgrade to powsybl dependencies 2024.2.0 (#145) Signed-off-by: Franck LECUYER --- pom.xml | 22 +------------------ .../server/NetworkConversionService.java | 11 ---------- .../server/NetworkConversionTest.java | 15 +++++++------ 3 files changed, 9 insertions(+), 39 deletions(-) diff --git a/pom.xml b/pom.xml index feac3f8..4b5a9c2 100644 --- a/pom.xml +++ b/pom.xml @@ -26,10 +26,8 @@ UTF-8 0.0.2 - 2.11.0 + 2.12.0 1.16.2 - - 1.13.0 @@ -65,24 +63,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} - 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 1767bca..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; @@ -407,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 9104a20..3b38276 100644 --- a/src/test/java/com/powsybl/network/conversion/server/NetworkConversionTest.java +++ b/src/test/java/com/powsybl/network/conversion/server/NetworkConversionTest.java @@ -373,13 +373,14 @@ public void testExportSv() throws Exception { .andReturn(); 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(Objects.requireNonNull(mvcResult.getResponse().getHeader("content-disposition")).contains("filename*=UTF-8''urn%3Auuid%3Ad400c631-75a0-4c30-8aed-832b0d282e73")); + 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 From 4193f0a61d41cdf456e948e4fa42cd754445ade7 Mon Sep 17 00:00:00 2001 From: etiennehomer Date: Fri, 23 Aug 2024 17:01:06 +0200 Subject: [PATCH 08/11] Override network store version to 1.15.0 (#146) Signed-off-by: Etienne Homer --- pom.xml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pom.xml b/pom.xml index 4b5a9c2..4756ff1 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,8 @@ 0.0.2 2.12.0 1.16.2 + + 1.15.0 @@ -63,6 +65,24 @@ + + + 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} + From 2738410fedd80ac90bbd55134c3e25ff50a32e93 Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Tue, 10 Sep 2024 17:05:04 +0200 Subject: [PATCH 09/11] upgrade network store to v1.16.0 Signed-off-by: Etienne LESOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4756ff1..155d693 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ 2.12.0 1.16.2 - 1.15.0 + 1.16.0 From dba57007a6466b939ba5fe893f54e7ff518568f7 Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Wed, 11 Sep 2024 16:56:48 +0200 Subject: [PATCH 10/11] fix network store upgrade Signed-off-by: Etienne LESOT --- pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pom.xml b/pom.xml index 155d693..235e9bc 100644 --- a/pom.xml +++ b/pom.xml @@ -125,10 +125,6 @@ com.powsybl powsybl-case-datasource-client - - com.powsybl - powsybl-network-store-client - com.powsybl powsybl-cgmes-conversion From 2c2942766b9d2c11a386e150697dea0d1afb1527 Mon Sep 17 00:00:00 2001 From: Etienne LESOT Date: Wed, 11 Sep 2024 17:00:14 +0200 Subject: [PATCH 11/11] fix Signed-off-by: Etienne LESOT --- pom.xml | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index 235e9bc..0597ad9 100644 --- a/pom.xml +++ b/pom.xml @@ -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,6 +105,25 @@ 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 powsybl-cgmes-conversion