From b811a4dac980fbb096d2940cb43d683ca8424436 Mon Sep 17 00:00:00 2001 From: dbraquart <107846716+dbraquart@users.noreply.github.com> Date: Mon, 26 Feb 2024 13:54:28 +0100 Subject: [PATCH] fix a copy-paste issue on an unexisting modification element (#77) --- .../explore/server/services/ExploreService.java | 9 ++++++--- .../java/org/gridsuite/explore/server/ExploreTest.java | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) 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 d966a7f5..bb70e4d2 100644 --- a/src/main/java/org/gridsuite/explore/server/services/ExploreService.java +++ b/src/main/java/org/gridsuite/explore/server/services/ExploreService.java @@ -277,9 +277,12 @@ public void createNetworkModifications(List modificationAttri // create all corresponding directory elements modificationAttributesList.forEach(m -> { final UUID newId = newModificationsUuids.get(m.getElementUuid()); - ElementAttributes elementAttributes = new ElementAttributes(newId, m.getElementName(), MODIFICATION, - null, userId, 0L, m.getDescription()); - directoryService.createElementWithNewName(elementAttributes, parentDirectoryUuid, userId, true); + if (newId != null) { + // an Id may be null if a duplication could not succeed (ex: we provide a bad uuid) + ElementAttributes elementAttributes = new ElementAttributes(newId, m.getElementName(), MODIFICATION, + null, userId, 0L, m.getDescription()); + directoryService.createElementWithNewName(elementAttributes, parentDirectoryUuid, userId, true); + } }); } } diff --git a/src/test/java/org/gridsuite/explore/server/ExploreTest.java b/src/test/java/org/gridsuite/explore/server/ExploreTest.java index f609a465..f3211032 100644 --- a/src/test/java/org/gridsuite/explore/server/ExploreTest.java +++ b/src/test/java/org/gridsuite/explore/server/ExploreTest.java @@ -673,7 +673,11 @@ public void testGetMetadata() throws Exception { @Test @SneakyThrows public void testcreateNetworkModifications() { - final String body = mapper.writeValueAsString(List.of(new ElementAttributes(MODIFICATION_UUID, "one modif", "", null, USER1, 0L, "a description"))); + final String body = mapper.writeValueAsString(List.of( + new ElementAttributes(MODIFICATION_UUID, "one modif", "", null, USER1, 0L, "a description"), + new ElementAttributes(UUID.randomUUID(), "2nd modif", "", null, USER1, 0L, "a description") + ) + ); mockMvc.perform(post("/v1/explore/modifications?parentDirectoryUuid={parentDirectoryUuid}", PARENT_DIRECTORY_UUID) .header("userId", USER1) .contentType(MediaType.APPLICATION_JSON)