From a9a1f9401b24ceca6e388f54a07f4e59da04bac3 Mon Sep 17 00:00:00 2001 From: Mathieu DEHARBE Date: Tue, 8 Oct 2024 14:49:21 +0200 Subject: [PATCH 01/11] get composite modification content endpoint --- .../explore/server/ExploreController.java | 9 +++++++++ .../explore/server/services/DirectoryService.java | 4 ++++ .../services/NetworkModificationService.java | 15 +++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/main/java/org/gridsuite/explore/server/ExploreController.java b/src/main/java/org/gridsuite/explore/server/ExploreController.java index b624e59..7e842f5 100644 --- a/src/main/java/org/gridsuite/explore/server/ExploreController.java +++ b/src/main/java/org/gridsuite/explore/server/ExploreController.java @@ -249,6 +249,15 @@ public ResponseEntity> getElementsMetadata(@RequestParam return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(directoryService.getElementsMetadata(ids, elementTypes, equipmentTypes)); } + @GetMapping(value = "/explore/network-composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE) // TODO : POURQUOI '/EXPLORE' ? + @Operation(summary = "get the network modifications infos contained in a composite network modification") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Infos from all the contained network modifications")}) + public ResponseEntity> getCompositeModificationContent(@PathVariable("id") UUID compositeModificationId) { // TODO : should probably be turned into List + return ResponseEntity.ok() + .contentType(MediaType.APPLICATION_JSON) + .body(directoryService.getCompositeModificationContent(compositeModificationId)); + } + @PutMapping(value = "/explore/filters/{id}", consumes = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Modify a filter") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The filter has been successfully modified")}) diff --git a/src/main/java/org/gridsuite/explore/server/services/DirectoryService.java b/src/main/java/org/gridsuite/explore/server/services/DirectoryService.java index 8af829b..2757f2b 100644 --- a/src/main/java/org/gridsuite/explore/server/services/DirectoryService.java +++ b/src/main/java/org/gridsuite/explore/server/services/DirectoryService.java @@ -243,6 +243,10 @@ private IDirectoryElementsService getGenericService(String type) { return iDirectoryElementsService; } + public List getCompositeModificationContent(UUID compositeModificationId) { + return ((NetworkModificationService) getGenericService(MODIFICATION)).getCompositeModificationContent(compositeModificationId); + } + public List getElementsMetadata(List ids, List elementTypes, List equipmentTypes) { Map> elementAttributesListByType = getElementsInfos(ids, elementTypes) diff --git a/src/main/java/org/gridsuite/explore/server/services/NetworkModificationService.java b/src/main/java/org/gridsuite/explore/server/services/NetworkModificationService.java index 255f90a..276a5db 100644 --- a/src/main/java/org/gridsuite/explore/server/services/NetworkModificationService.java +++ b/src/main/java/org/gridsuite/explore/server/services/NetworkModificationService.java @@ -87,4 +87,19 @@ public List> getMetadata(List modificationUuids) { new ParameterizedTypeReference>>() { }).getBody(); } + + public List getCompositeModificationContent(UUID compositeModificationId) { + String path = UriComponentsBuilder + .fromPath(DELIMITER + + NETWORK_MODIFICATION_API_VERSION + + DELIMITER + + "/network-composite-modification/" + + compositeModificationId) + .buildAndExpand() + .toUriString(); + List body = restTemplate.exchange(networkModificationServerBaseUri + path, HttpMethod.GET, null, + new ParameterizedTypeReference>() { + }).getBody(); + return body; + } } From c4bc80e193b1636da189c7be14862b0adcfa6ce9 Mon Sep 17 00:00:00 2001 From: Mathieu DEHARBE Date: Tue, 22 Oct 2024 16:53:47 +0200 Subject: [PATCH 02/11] code coverage --- .../explore/server/ExploreController.java | 4 +-- .../services/NetworkModificationService.java | 3 +- .../gridsuite/explore/server/ExploreTest.java | 33 ++++++++++++++++++- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gridsuite/explore/server/ExploreController.java b/src/main/java/org/gridsuite/explore/server/ExploreController.java index 7e842f5..06b2ddb 100644 --- a/src/main/java/org/gridsuite/explore/server/ExploreController.java +++ b/src/main/java/org/gridsuite/explore/server/ExploreController.java @@ -249,10 +249,10 @@ public ResponseEntity> getElementsMetadata(@RequestParam return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(directoryService.getElementsMetadata(ids, elementTypes, equipmentTypes)); } - @GetMapping(value = "/explore/network-composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE) // TODO : POURQUOI '/EXPLORE' ? + @GetMapping(value = "/explore/network-composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "get the network modifications infos contained in a composite network modification") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Infos from all the contained network modifications")}) - public ResponseEntity> getCompositeModificationContent(@PathVariable("id") UUID compositeModificationId) { // TODO : should probably be turned into List + public ResponseEntity> getCompositeModificationContent(@PathVariable("id") UUID compositeModificationId) { return ResponseEntity.ok() .contentType(MediaType.APPLICATION_JSON) .body(directoryService.getCompositeModificationContent(compositeModificationId)); diff --git a/src/main/java/org/gridsuite/explore/server/services/NetworkModificationService.java b/src/main/java/org/gridsuite/explore/server/services/NetworkModificationService.java index 276a5db..b8ed442 100644 --- a/src/main/java/org/gridsuite/explore/server/services/NetworkModificationService.java +++ b/src/main/java/org/gridsuite/explore/server/services/NetworkModificationService.java @@ -97,9 +97,8 @@ public List getCompositeModificationContent(UUID compositeModificationId compositeModificationId) .buildAndExpand() .toUriString(); - List body = restTemplate.exchange(networkModificationServerBaseUri + path, HttpMethod.GET, null, + return restTemplate.exchange(networkModificationServerBaseUri + path, HttpMethod.GET, null, new ParameterizedTypeReference>() { }).getBody(); - return body; } } diff --git a/src/test/java/org/gridsuite/explore/server/ExploreTest.java b/src/test/java/org/gridsuite/explore/server/ExploreTest.java index a6d29e9..e7bbf74 100644 --- a/src/test/java/org/gridsuite/explore/server/ExploreTest.java +++ b/src/test/java/org/gridsuite/explore/server/ExploreTest.java @@ -73,6 +73,7 @@ public class ExploreTest { private static final UUID INVALID_ELEMENT_UUID = UUID.randomUUID(); private static final UUID PARAMETERS_UUID = UUID.randomUUID(); private static final UUID MODIFICATION_UUID = UUID.randomUUID(); + private static final UUID COMPOSITE_MODIFICATION_UUID = UUID.randomUUID(); private static final UUID STUDY_COPY_UUID = UUID.randomUUID(); private static final UUID CASE_COPY_UUID = UUID.randomUUID(); private static final UUID CONTINGENCY_LIST_COPY_UUID = UUID.randomUUID(); @@ -93,6 +94,20 @@ public class ExploreTest { private final Map specificMetadata2 = Map.of("equipmentType", "LINE", "id", FILTER_UUID_2); private final Map caseSpecificMetadata = Map.of("uuid", CASE_UUID, "name", TEST_FILE, "format", "XIIDM"); private final Map modificationSpecificMetadata = Map.of("id", MODIFICATION_UUID, "type", "LOAD_MODIFICATION"); + private final List> compositeModificationMetadata = List.of( + Map.of( + "uuid", MODIFICATION_UUID, + "type", "LOAD_MODIFICATION", + "messageType", "LOAD_MODIFICATION", + "messageValues", "{\"equipmentId\":\"VERSA6T611\"}", + "activated", true), + Map.of( + "uuid", MODIFICATION_UUID, + "type", "SHUNT_COMPENSATOR_MODIFICATION", + "messageType", "SHUNT_COMPENSATOR_MODIFICATION", + "messageValues", "{\"equipmentId\":\"MERLA4COND.31\"}", + "activated", true) + ); private static final UUID SCRIPT_ID_BASE_FORM_CONTINGENCY_LIST_UUID = UUID.randomUUID(); private static final UUID ELEMENT_UUID = UUID.randomUUID(); @@ -318,7 +333,12 @@ public MockResponse dispatch(RecordedRequest request) { } else if (path.matches("/v1/cases/metadata[?]ids=" + CASE_UUID)) { return new MockResponse().setBody(caseInfosAttributesAsString).setResponseCode(200).addHeader("Content-Type", "application/json; charset=utf-8"); } else if (path.matches("/v1/network-modifications/metadata[?]ids=" + MODIFICATION_UUID)) { - return new MockResponse().setBody(modificationInfosAttributesAsString).setResponseCode(200).addHeader("Content-Type", "application/json; charset=utf-8"); + return new MockResponse().setBody(modificationInfosAttributesAsString) + .setResponseCode(200).addHeader("Content-Type", "application/json; charset=utf-8"); + } else if (path.matches("/v1/network-composite-modification/" + COMPOSITE_MODIFICATION_UUID)) { + return new MockResponse().setBody(mapper.writeValueAsString(compositeModificationMetadata)) + .setResponseCode(200) + .addHeader("Content-Type", "application/json; charset=utf-8"); } else if (path.matches("/v1/studies/metadata[?]ids=" + PRIVATE_STUDY_UUID)) { return new MockResponse().setBody(listOfPrivateStudyAttributesAsString.replace("elementUuid", "id")).setResponseCode(200) .addHeader("Content-Type", "application/json; charset=utf-8"); @@ -799,6 +819,17 @@ public void testGetModificationMetadata() { assertEquals(mapper.writeValueAsString(elementsMetadata.get(0)), expectedResult); } + @Test + public void testGetCompositeModificationContent() throws Exception { + MvcResult result = mockMvc.perform(get("/v1/explore/network-composite-modification/" + COMPOSITE_MODIFICATION_UUID) + .header("userId", USER1) + ).andExpect(status().isOk()) + .andReturn(); + String response = result.getResponse().getContentAsString(); + List> metadata = mapper.readValue(response, new TypeReference<>() { }); + assertEquals(2, metadata.size()); + } + @Test public void testMaxCaseCreationExceeded() throws Exception { From a91ae9dd7b88e63ee232d8f58337f96d8a280710 Mon Sep 17 00:00:00 2001 From: Mathieu DEHARBE Date: Thu, 24 Oct 2024 13:32:08 +0200 Subject: [PATCH 03/11] rename --- .../java/org/gridsuite/explore/server/ExploreTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/gridsuite/explore/server/ExploreTest.java b/src/test/java/org/gridsuite/explore/server/ExploreTest.java index e7bbf74..bce7a09 100644 --- a/src/test/java/org/gridsuite/explore/server/ExploreTest.java +++ b/src/test/java/org/gridsuite/explore/server/ExploreTest.java @@ -73,6 +73,7 @@ public class ExploreTest { private static final UUID INVALID_ELEMENT_UUID = UUID.randomUUID(); private static final UUID PARAMETERS_UUID = UUID.randomUUID(); private static final UUID MODIFICATION_UUID = UUID.randomUUID(); + private static final UUID MODIFICATION2_UUID = UUID.randomUUID(); private static final UUID COMPOSITE_MODIFICATION_UUID = UUID.randomUUID(); private static final UUID STUDY_COPY_UUID = UUID.randomUUID(); private static final UUID CASE_COPY_UUID = UUID.randomUUID(); @@ -99,13 +100,13 @@ public class ExploreTest { "uuid", MODIFICATION_UUID, "type", "LOAD_MODIFICATION", "messageType", "LOAD_MODIFICATION", - "messageValues", "{\"equipmentId\":\"VERSA6T611\"}", + "messageValues", "{\"equipmentId\":\"equipmentId1\"}", "activated", true), Map.of( - "uuid", MODIFICATION_UUID, + "uuid", MODIFICATION2_UUID, "type", "SHUNT_COMPENSATOR_MODIFICATION", "messageType", "SHUNT_COMPENSATOR_MODIFICATION", - "messageValues", "{\"equipmentId\":\"MERLA4COND.31\"}", + "messageValues", "{\"equipmentId\":\"equipmentId2\"}", "activated", true) ); From 3c938cfd87376f9daa9dff6bc41bb9206a4ad781 Mon Sep 17 00:00:00 2001 From: Mathieu DEHARBE Date: Thu, 24 Oct 2024 17:15:01 +0200 Subject: [PATCH 04/11] corrections post merge conflicts --- .../org/gridsuite/explore/server/ExploreTest.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/gridsuite/explore/server/ExploreTest.java b/src/test/java/org/gridsuite/explore/server/ExploreTest.java index 7c26a71..174dacc 100644 --- a/src/test/java/org/gridsuite/explore/server/ExploreTest.java +++ b/src/test/java/org/gridsuite/explore/server/ExploreTest.java @@ -307,11 +307,13 @@ public MockResponse dispatch(RecordedRequest request) { } else if (path.matches("/v1/cases/metadata[?]ids=" + CASE_UUID)) { return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), caseInfosAttributesAsString); } else if (path.matches("/v1/network-modifications/metadata[?]ids=" + MODIFICATION_UUID)) { - return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), modificationInfosAttributesAsString); + return new MockResponse(200, + Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), + modificationInfosAttributesAsString); } else if (path.matches("/v1/network-composite-modification/" + COMPOSITE_MODIFICATION_UUID)) { - return new MockResponse().setBody(mapper.writeValueAsString(compositeModificationMetadata)) - .setResponseCode(200) - .addHeader("Content-Type", "application/json; charset=utf-8"); + return new MockResponse(200, + Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), + mapper.writeValueAsString(compositeModificationMetadata)); } else if (path.matches("/v1/studies/metadata[?]ids=" + PRIVATE_STUDY_UUID)) { return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), listOfPrivateStudyAttributesAsString.replace("elementUuid", "id")); } else if (path.matches("/v1/users/" + USER_WITH_CASE_LIMIT_EXCEEDED + "/profile/max-cases")) { @@ -787,7 +789,8 @@ void testGetModificationMetadata() throws Exception { assertEquals(mapper.writeValueAsString(elementsMetadata.get(0)), expectedResult); } - public void testGetCompositeModificationContent() throws Exception { + @Test + void testGetCompositeModificationContent() throws Exception { MvcResult result = mockMvc.perform(get("/v1/explore/network-composite-modification/" + COMPOSITE_MODIFICATION_UUID) .header("userId", USER1) ).andExpect(status().isOk()) From 2185fd86fd7021db39b709854a8dea9c7a7f9e30 Mon Sep 17 00:00:00 2001 From: Mathieu DEHARBE Date: Thu, 24 Oct 2024 17:53:30 +0200 Subject: [PATCH 05/11] allow renaming of composite modification Signed-off-by: Mathieu DEHARBE --- .../explore/server/ExploreController.java | 14 +++++++++++++- .../explore/server/services/ExploreService.java | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gridsuite/explore/server/ExploreController.java b/src/main/java/org/gridsuite/explore/server/ExploreController.java index 6385b4a..5fd19f6 100644 --- a/src/main/java/org/gridsuite/explore/server/ExploreController.java +++ b/src/main/java/org/gridsuite/explore/server/ExploreController.java @@ -268,7 +268,7 @@ public ResponseEntity changeFilter(@PathVariable UUID id, @RequestBody Str @PutMapping(value = "/explore/contingency-lists/{id}", consumes = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Modify a contingency list") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The contingency list have been modified successfully")}) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The contingency list has been modified successfully")}) public ResponseEntity updateContingencyList( @PathVariable UUID id, @RequestParam(name = "name") String name, @@ -280,6 +280,18 @@ public ResponseEntity updateContingencyList( return ResponseEntity.ok().build(); } + @PutMapping(value = "/explore/composite-modification/{id}", consumes = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Modify a composite modification") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The composite modification has been modified successfully")}) + public ResponseEntity updateCompositeModification( + @PathVariable UUID id, + @RequestParam(name = "name") String name, + @RequestHeader(QUERY_PARAM_USER_ID) String userId) { + + exploreService.updateCompositeModification(id, userId, name); + return ResponseEntity.ok().build(); + } + @PostMapping(value = "/explore/parameters", consumes = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "create parameters") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "parameters creation request delegated to corresponding server")}) diff --git a/src/main/java/org/gridsuite/explore/server/services/ExploreService.java b/src/main/java/org/gridsuite/explore/server/services/ExploreService.java index a6700ba..9a3a9bc 100644 --- a/src/main/java/org/gridsuite/explore/server/services/ExploreService.java +++ b/src/main/java/org/gridsuite/explore/server/services/ExploreService.java @@ -216,6 +216,10 @@ public void updateContingencyList(UUID id, String content, String userId, String updateElementName(id, name, userId); } + public void updateCompositeModification(UUID id, String userId, String name) { + updateElementName(id, name, userId); + } + private void updateElementName(UUID id, String name, String userId) { // if the name is empty, no need to call directory-server if (StringUtils.isNotBlank(name)) { From 5aff44e0d05e78a41cb3cacce3b19b7ed75425fc Mon Sep 17 00:00:00 2001 From: Mathieu DEHARBE Date: Thu, 24 Oct 2024 18:10:05 +0200 Subject: [PATCH 06/11] code coverage Signed-off-by: Mathieu DEHARBE --- .../explore/server/ExploreController.java | 6 +++--- .../org/gridsuite/explore/server/ExploreTest.java | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gridsuite/explore/server/ExploreController.java b/src/main/java/org/gridsuite/explore/server/ExploreController.java index 5fd19f6..581b014 100644 --- a/src/main/java/org/gridsuite/explore/server/ExploreController.java +++ b/src/main/java/org/gridsuite/explore/server/ExploreController.java @@ -249,8 +249,8 @@ public ResponseEntity> getElementsMetadata(@RequestParam return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(directoryService.getElementsMetadata(ids, elementTypes, equipmentTypes)); } - @GetMapping(value = "/explore/network-composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - @Operation(summary = "get the network modifications infos contained in a composite network modification") + @GetMapping(value = "/explore/composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "get the network modifications infos contained in a composite modification") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Infos from all the contained network modifications")}) public ResponseEntity> getCompositeModificationContent(@PathVariable("id") UUID compositeModificationId) { return ResponseEntity.ok() @@ -268,7 +268,7 @@ public ResponseEntity changeFilter(@PathVariable UUID id, @RequestBody Str @PutMapping(value = "/explore/contingency-lists/{id}", consumes = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "Modify a contingency list") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The contingency list has been modified successfully")}) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The contingency list have been modified successfully")}) public ResponseEntity updateContingencyList( @PathVariable UUID id, @RequestParam(name = "name") String name, diff --git a/src/test/java/org/gridsuite/explore/server/ExploreTest.java b/src/test/java/org/gridsuite/explore/server/ExploreTest.java index 174dacc..29c0759 100644 --- a/src/test/java/org/gridsuite/explore/server/ExploreTest.java +++ b/src/test/java/org/gridsuite/explore/server/ExploreTest.java @@ -314,6 +314,8 @@ public MockResponse dispatch(RecordedRequest request) { return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), mapper.writeValueAsString(compositeModificationMetadata)); + } else if (path.matches("/v1/network-composite-modification/.*") && "PUT".equals(request.getMethod())) { + return new MockResponse(200); } else if (path.matches("/v1/studies/metadata[?]ids=" + PRIVATE_STUDY_UUID)) { return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), listOfPrivateStudyAttributesAsString.replace("elementUuid", "id")); } else if (path.matches("/v1/users/" + USER_WITH_CASE_LIMIT_EXCEEDED + "/profile/max-cases")) { @@ -776,6 +778,17 @@ void testCreateNetworkCompositeModifications() throws Exception { ).andExpect(status().isOk()); } + @Test + void testModifyCompositeModifications(final MockWebServer server) throws Exception { + final String scriptContingency = "{\"script\":\"alert(\\\"script contingency\\\")\"}"; + final String name = "script name"; + mockMvc.perform(put("/v1/explore/composite-modification/{id}") + .contentType(APPLICATION_JSON) + .param("name", name) + .header("userId", USER1) + ).andExpect(status().isOk()); + } + @Test void testGetModificationMetadata() throws Exception { final String expectedResult = mapper.writeValueAsString(new ElementAttributes(MODIFICATION_UUID, "one modif", "MODIFICATION", USER1, 0L, null, modificationSpecificMetadata)); @@ -791,7 +804,7 @@ void testGetModificationMetadata() throws Exception { @Test void testGetCompositeModificationContent() throws Exception { - MvcResult result = mockMvc.perform(get("/v1/explore/network-composite-modification/" + COMPOSITE_MODIFICATION_UUID) + MvcResult result = mockMvc.perform(get("/v1/explore/composite-modification/" + COMPOSITE_MODIFICATION_UUID) .header("userId", USER1) ).andExpect(status().isOk()) .andReturn(); From 3b88f5f8ac9fb19887431bc39bfcc437aeb05438 Mon Sep 17 00:00:00 2001 From: Mathieu DEHARBE Date: Thu, 24 Oct 2024 18:19:32 +0200 Subject: [PATCH 07/11] correct TU Signed-off-by: Mathieu DEHARBE --- .../java/org/gridsuite/explore/server/ExploreTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/gridsuite/explore/server/ExploreTest.java b/src/test/java/org/gridsuite/explore/server/ExploreTest.java index 29c0759..4ed39f9 100644 --- a/src/test/java/org/gridsuite/explore/server/ExploreTest.java +++ b/src/test/java/org/gridsuite/explore/server/ExploreTest.java @@ -782,10 +782,11 @@ void testCreateNetworkCompositeModifications() throws Exception { void testModifyCompositeModifications(final MockWebServer server) throws Exception { final String scriptContingency = "{\"script\":\"alert(\\\"script contingency\\\")\"}"; final String name = "script name"; - mockMvc.perform(put("/v1/explore/composite-modification/{id}") - .contentType(APPLICATION_JSON) - .param("name", name) - .header("userId", USER1) + mockMvc.perform( + put("/v1/explore/composite-modification/{id}",COMPOSITE_MODIFICATION_UUID) + .contentType(APPLICATION_JSON) + .param("name", name) + .header("userId", USER1) ).andExpect(status().isOk()); } From 82a74de10dd260256fa0d69d63eeae177a87744b Mon Sep 17 00:00:00 2001 From: Mathieu DEHARBE Date: Thu, 24 Oct 2024 18:24:28 +0200 Subject: [PATCH 08/11] space Signed-off-by: Mathieu DEHARBE --- src/test/java/org/gridsuite/explore/server/ExploreTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/gridsuite/explore/server/ExploreTest.java b/src/test/java/org/gridsuite/explore/server/ExploreTest.java index 4ed39f9..17c4e16 100644 --- a/src/test/java/org/gridsuite/explore/server/ExploreTest.java +++ b/src/test/java/org/gridsuite/explore/server/ExploreTest.java @@ -783,7 +783,7 @@ void testModifyCompositeModifications(final MockWebServer server) throws Excepti final String scriptContingency = "{\"script\":\"alert(\\\"script contingency\\\")\"}"; final String name = "script name"; mockMvc.perform( - put("/v1/explore/composite-modification/{id}",COMPOSITE_MODIFICATION_UUID) + put("/v1/explore/composite-modification/{id}", COMPOSITE_MODIFICATION_UUID) .contentType(APPLICATION_JSON) .param("name", name) .header("userId", USER1) From 90955a5894c437db4e72523755930e9ec6b5f95e Mon Sep 17 00:00:00 2001 From: Mathieu DEHARBE Date: Thu, 24 Oct 2024 18:30:31 +0200 Subject: [PATCH 09/11] cleaning Signed-off-by: Mathieu DEHARBE --- src/test/java/org/gridsuite/explore/server/ExploreTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/gridsuite/explore/server/ExploreTest.java b/src/test/java/org/gridsuite/explore/server/ExploreTest.java index 17c4e16..feca5bd 100644 --- a/src/test/java/org/gridsuite/explore/server/ExploreTest.java +++ b/src/test/java/org/gridsuite/explore/server/ExploreTest.java @@ -780,7 +780,6 @@ void testCreateNetworkCompositeModifications() throws Exception { @Test void testModifyCompositeModifications(final MockWebServer server) throws Exception { - final String scriptContingency = "{\"script\":\"alert(\\\"script contingency\\\")\"}"; final String name = "script name"; mockMvc.perform( put("/v1/explore/composite-modification/{id}", COMPOSITE_MODIFICATION_UUID) From 245493cd014a216ded5f5f116b9b8dc0d66be262 Mon Sep 17 00:00:00 2001 From: Mathieu DEHARBE Date: Wed, 30 Oct 2024 11:39:40 +0100 Subject: [PATCH 10/11] moved getCompositeModificationContent to explore service Signed-off-by: Mathieu DEHARBE --- .../org/gridsuite/explore/server/ExploreController.java | 6 +++--- .../gridsuite/explore/server/services/DirectoryService.java | 4 ---- .../gridsuite/explore/server/services/ExploreService.java | 4 ++++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gridsuite/explore/server/ExploreController.java b/src/main/java/org/gridsuite/explore/server/ExploreController.java index bf01765..e72a117 100644 --- a/src/main/java/org/gridsuite/explore/server/ExploreController.java +++ b/src/main/java/org/gridsuite/explore/server/ExploreController.java @@ -250,12 +250,12 @@ public ResponseEntity> getElementsMetadata(@RequestParam } @GetMapping(value = "/explore/composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - @Operation(summary = "get the network modifications infos contained in a composite modification") - @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Infos from all the contained network modifications")}) + @Operation(summary = "get the basic information of the network modifications contained in a composite modification") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Basic infos from all the contained network modifications")}) public ResponseEntity> getCompositeModificationContent(@PathVariable("id") UUID compositeModificationId) { return ResponseEntity.ok() .contentType(MediaType.APPLICATION_JSON) - .body(directoryService.getCompositeModificationContent(compositeModificationId)); + .body(exploreService.getCompositeModificationContent(compositeModificationId)); } @PutMapping(value = "/explore/filters/{id}", consumes = MediaType.APPLICATION_JSON_VALUE) diff --git a/src/main/java/org/gridsuite/explore/server/services/DirectoryService.java b/src/main/java/org/gridsuite/explore/server/services/DirectoryService.java index c60341b..0583c64 100644 --- a/src/main/java/org/gridsuite/explore/server/services/DirectoryService.java +++ b/src/main/java/org/gridsuite/explore/server/services/DirectoryService.java @@ -241,10 +241,6 @@ private IDirectoryElementsService getGenericService(String type) { return iDirectoryElementsService; } - public List getCompositeModificationContent(UUID compositeModificationId) { - return ((NetworkModificationService) getGenericService(MODIFICATION)).getCompositeModificationContent(compositeModificationId); - } - public List getElementsMetadata(List ids, List elementTypes, List equipmentTypes) { Map> elementAttributesListByType = getElementsInfos(ids, elementTypes) diff --git a/src/main/java/org/gridsuite/explore/server/services/ExploreService.java b/src/main/java/org/gridsuite/explore/server/services/ExploreService.java index 2db1376..84e2f7c 100644 --- a/src/main/java/org/gridsuite/explore/server/services/ExploreService.java +++ b/src/main/java/org/gridsuite/explore/server/services/ExploreService.java @@ -220,6 +220,10 @@ public void updateCompositeModification(UUID id, String userId, String name) { updateElementName(id, name, userId); } + public List getCompositeModificationContent(UUID compositeModificationId) { + return networkModificationService.getCompositeModificationContent(compositeModificationId); + } + private void updateElementName(UUID id, String name, String userId) { // if the name is empty, no need to call directory-server if (StringUtils.isNotBlank(name)) { From 75b70279755baefcd7c528011bf13bd53c6243e9 Mon Sep 17 00:00:00 2001 From: Mathieu DEHARBE Date: Thu, 31 Oct 2024 17:05:01 +0100 Subject: [PATCH 11/11] updated endpoint Signed-off-by: Mathieu DEHARBE --- .../java/org/gridsuite/explore/server/ExploreController.java | 2 +- .../explore/server/services/NetworkModificationService.java | 3 ++- src/test/java/org/gridsuite/explore/server/ExploreTest.java | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gridsuite/explore/server/ExploreController.java b/src/main/java/org/gridsuite/explore/server/ExploreController.java index e72a117..141c8c9 100644 --- a/src/main/java/org/gridsuite/explore/server/ExploreController.java +++ b/src/main/java/org/gridsuite/explore/server/ExploreController.java @@ -249,7 +249,7 @@ public ResponseEntity> getElementsMetadata(@RequestParam return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(directoryService.getElementsMetadata(ids, elementTypes, equipmentTypes)); } - @GetMapping(value = "/explore/composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + @GetMapping(value = "/explore/composite-modification/{id}/network-modifications", produces = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "get the basic information of the network modifications contained in a composite modification") @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Basic infos from all the contained network modifications")}) public ResponseEntity> getCompositeModificationContent(@PathVariable("id") UUID compositeModificationId) { diff --git a/src/main/java/org/gridsuite/explore/server/services/NetworkModificationService.java b/src/main/java/org/gridsuite/explore/server/services/NetworkModificationService.java index 7237f7c..c0ee118 100644 --- a/src/main/java/org/gridsuite/explore/server/services/NetworkModificationService.java +++ b/src/main/java/org/gridsuite/explore/server/services/NetworkModificationService.java @@ -92,7 +92,8 @@ public List getCompositeModificationContent(UUID compositeModificationId NETWORK_MODIFICATION_API_VERSION + DELIMITER + "/network-composite-modification/" + - compositeModificationId) + compositeModificationId + + "/network-modifications") .buildAndExpand() .toUriString(); return restTemplate.exchange(networkModificationServerBaseUri + path, HttpMethod.GET, null, diff --git a/src/test/java/org/gridsuite/explore/server/ExploreTest.java b/src/test/java/org/gridsuite/explore/server/ExploreTest.java index ffa651a..95d4261 100644 --- a/src/test/java/org/gridsuite/explore/server/ExploreTest.java +++ b/src/test/java/org/gridsuite/explore/server/ExploreTest.java @@ -310,7 +310,7 @@ public MockResponse dispatch(RecordedRequest request) { return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), modificationInfosAttributesAsString); - } else if (path.matches("/v1/network-composite-modification/" + COMPOSITE_MODIFICATION_UUID)) { + } else if (path.matches("/v1/network-composite-modification/" + COMPOSITE_MODIFICATION_UUID + "/network-modifications")) { return new MockResponse(200, Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), mapper.writeValueAsString(compositeModificationMetadata)); @@ -804,7 +804,7 @@ void testGetModificationMetadata() throws Exception { @Test void testGetCompositeModificationContent() throws Exception { - MvcResult result = mockMvc.perform(get("/v1/explore/composite-modification/" + COMPOSITE_MODIFICATION_UUID) + MvcResult result = mockMvc.perform(get("/v1/explore/composite-modification/" + COMPOSITE_MODIFICATION_UUID + "/network-modifications") .header("userId", USER1) ).andExpect(status().isOk()) .andReturn();