diff --git a/src/main/java/org/gridsuite/explore/server/ExploreController.java b/src/main/java/org/gridsuite/explore/server/ExploreController.java index 7616016..bf415b7 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/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) { + return ResponseEntity.ok() + .contentType(MediaType.APPLICATION_JSON) + .body(exploreService.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")}) @@ -271,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 0194714..f5c80fd 100644 --- a/src/main/java/org/gridsuite/explore/server/services/ExploreService.java +++ b/src/main/java/org/gridsuite/explore/server/services/ExploreService.java @@ -221,6 +221,14 @@ 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); + } + + 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)) { 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 0315133..c0ee118 100644 --- a/src/main/java/org/gridsuite/explore/server/services/NetworkModificationService.java +++ b/src/main/java/org/gridsuite/explore/server/services/NetworkModificationService.java @@ -85,4 +85,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 + + "/network-modifications") + .buildAndExpand() + .toUriString(); + return restTemplate.exchange(networkModificationServerBaseUri + path, HttpMethod.GET, null, + new ParameterizedTypeReference>() { + }).getBody(); + } } diff --git a/src/test/java/org/gridsuite/explore/server/ExploreTest.java b/src/test/java/org/gridsuite/explore/server/ExploreTest.java index 11536de..95d4261 100644 --- a/src/test/java/org/gridsuite/explore/server/ExploreTest.java +++ b/src/test/java/org/gridsuite/explore/server/ExploreTest.java @@ -75,6 +75,8 @@ 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(); private static final UUID CONTINGENCY_LIST_COPY_UUID = UUID.randomUUID(); @@ -97,6 +99,20 @@ 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\":\"equipmentId1\"}", + "activated", true), + Map.of( + "uuid", MODIFICATION2_UUID, + "type", "SHUNT_COMPENSATOR_MODIFICATION", + "messageType", "SHUNT_COMPENSATOR_MODIFICATION", + "messageValues", "{\"equipmentId\":\"equipmentId2\"}", + "activated", true) + ); private static final UUID SCRIPT_ID_BASE_FORM_CONTINGENCY_LIST_UUID = UUID.randomUUID(); private static final UUID ELEMENT_UUID = UUID.randomUUID(); @@ -291,7 +307,15 @@ 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 + "/network-modifications")) { + 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")) { @@ -754,6 +778,17 @@ void testCreateNetworkCompositeModifications() throws Exception { ).andExpect(status().isOk()); } + @Test + void testModifyCompositeModifications(final MockWebServer server) throws Exception { + final String name = "script name"; + mockMvc.perform( + put("/v1/explore/composite-modification/{id}", COMPOSITE_MODIFICATION_UUID) + .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)); @@ -767,6 +802,17 @@ void testGetModificationMetadata() throws Exception { assertEquals(mapper.writeValueAsString(elementsMetadata.get(0)), expectedResult); } + @Test + void testGetCompositeModificationContent() throws Exception { + MvcResult result = mockMvc.perform(get("/v1/explore/composite-modification/" + COMPOSITE_MODIFICATION_UUID + "/network-modifications") + .header("userId", USER1) + ).andExpect(status().isOk()) + .andReturn(); + String response = result.getResponse().getContentAsString(); + List> metadata = mapper.readValue(response, new TypeReference<>() { }); + assertEquals(2, metadata.size()); + } + @Test void testMaxCaseCreationExceeded() throws Exception { //test create a study with a user that already exceeded his cases limit