From 85fd6badf85e652e92024328880a605c71bbbb90 Mon Sep 17 00:00:00 2001 From: basseche Date: Thu, 9 Jan 2025 11:01:44 +0100 Subject: [PATCH] update filter request updates also element description. (#114) * update filter request, updates also description Signed-off-by: basseche --- .../gridsuite/explore/server/ExploreController.java | 5 +++-- .../explore/server/services/ExploreService.java | 10 ++++++++-- .../java/org/gridsuite/explore/server/ExploreTest.java | 2 ++ 3 files changed, 13 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 2b05136..ce25edd 100644 --- a/src/main/java/org/gridsuite/explore/server/ExploreController.java +++ b/src/main/java/org/gridsuite/explore/server/ExploreController.java @@ -261,8 +261,9 @@ public ResponseEntity> getCompositeModificationContent(@PathVariabl @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")}) - public ResponseEntity changeFilter(@PathVariable UUID id, @RequestBody String filter, @RequestHeader(QUERY_PARAM_USER_ID) String userId, @RequestParam("name") String name) { - exploreService.updateFilter(id, filter, userId, name); + public ResponseEntity changeFilter(@PathVariable UUID id, @RequestBody String filter, @RequestHeader(QUERY_PARAM_USER_ID) String userId, + @RequestParam("name") String name, @RequestParam("description") String description) { + exploreService.updateFilter(id, filter, userId, name, description); return ResponseEntity.ok().build(); } 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 d1fdb35..4550a56 100644 --- a/src/main/java/org/gridsuite/explore/server/services/ExploreService.java +++ b/src/main/java/org/gridsuite/explore/server/services/ExploreService.java @@ -215,9 +215,15 @@ public void deleteElementsFromDirectory(List uuids, UUID parentDirectoryUu } } - public void updateFilter(UUID id, String filter, String userId, String name) { + public void updateFilter(UUID id, String filter, String userId, String name, String description) { filterService.updateFilter(id, filter, userId); - updateElementName(id, name, userId); + + ElementAttributes elementAttributes = new ElementAttributes(); + elementAttributes.setDescription(description); + if (StringUtils.isNotBlank(name)) { + elementAttributes.setElementName(name); + } + directoryService.updateElement(id, elementAttributes, userId); } public void updateContingencyList(UUID id, String content, String userId, String name, ContingencyListType contingencyListType) { diff --git a/src/test/java/org/gridsuite/explore/server/ExploreTest.java b/src/test/java/org/gridsuite/explore/server/ExploreTest.java index 95d4261..e641b01 100644 --- a/src/test/java/org/gridsuite/explore/server/ExploreTest.java +++ b/src/test/java/org/gridsuite/explore/server/ExploreTest.java @@ -689,11 +689,13 @@ void testCaseCreationErrorWithBadExtension() throws Exception { void testChangeFilter(final MockWebServer server) throws Exception { final String filter = "{\"type\":\"CRITERIA\",\"equipmentFilterForm\":{\"equipmentType\":\"BATTERY\",\"name\":\"test bbs\",\"countries\":[\"BS\"],\"nominalVoltage\":{\"type\":\"LESS_THAN\",\"value1\":545430,\"value2\":null},\"freeProperties\":{\"region\":[\"north\"],\"totallyFree\":[\"6555\"],\"tso\":[\"ceps\"]}}}"; final String name = "filter name"; + final String description = "new filter description"; mockMvc.perform(put("/v1/explore/filters/{id}", FILTER_UUID) .contentType(APPLICATION_JSON) .content(filter) .param("name", name) + .param("description", description) .header("userId", USER1) ).andExpect(status().isOk());