From 6fe2244264bc0d8caccf047319b6c1c97460383c Mon Sep 17 00:00:00 2001 From: David BRAQUART Date: Thu, 22 Feb 2024 19:51:56 +0100 Subject: [PATCH] fix a copy-paste issue on a dead element --- .../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 3a5d8629..a7bcba8b 100644 --- a/src/main/java/org/gridsuite/explore/server/services/ExploreService.java +++ b/src/main/java/org/gridsuite/explore/server/services/ExploreService.java @@ -266,9 +266,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 cd749a95..1d97fbb4 100644 --- a/src/test/java/org/gridsuite/explore/server/ExploreTest.java +++ b/src/test/java/org/gridsuite/explore/server/ExploreTest.java @@ -662,7 +662,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)