diff --git a/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java b/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java index eb2f06e16..f64ce4575 100644 --- a/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java +++ b/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java @@ -128,7 +128,7 @@ public List getModifications(UUID groupUuid, boolean onlyMeta } } - private List getModificationsMetadata(UUID groupUuid, boolean stashedModifications) { + public List getModificationsMetadata(UUID groupUuid, boolean stashedModifications) { return modificationRepository .findAllBaseByGroupId(getModificationGroup(groupUuid).getId()) .stream() @@ -206,7 +206,7 @@ public List getModificationsEntities(@NonNull List uui @Transactional(readOnly = true) public List copyModificationsEntities(@NonNull UUID groupUuid) { - return getModificationEntityStream(groupUuid).map(ModificationEntity::copy).collect(Collectors.toList()); + return getModificationEntityStream(groupUuid).filter(m -> !m.getStashed()).map(ModificationEntity::copy).collect(Collectors.toList()); } @Transactional diff --git a/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java b/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java index c982ae761..1e800d2c8 100644 --- a/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java +++ b/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java @@ -756,12 +756,30 @@ public void testDuplicateModificationGroup() throws Exception { assertApplicationStatusOK(mvcResult); testNetworkModificationsCount(TEST_GROUP_ID, 5); - //test copy group + // get list of modifications + List modifications = modificationRepository.getModifications(TEST_GROUP_ID, true, true, false); + assertEquals(5, modifications.size()); + //stash the first modification + String uuidString = modifications.get(0).getUuid().toString(); + + mockMvc.perform(post(URI_NETWORK_MODIF_BASE + "/stash") + .queryParam("groupUuid", TEST_GROUP_ID.toString()) + .queryParam("uuids", uuidString)) + .andExpect(status().isOk()); + List stashedModifications = modificationRepository.getModificationsMetadata(TEST_GROUP_ID, true); + List modificationAfterStash = modificationRepository.getModificationsMetadata(TEST_GROUP_ID, false); + assertEquals(1, stashedModifications.size()); + assertEquals(4, modificationAfterStash.size()); + + //test copy group with stashed modification UUID newGroupUuid = UUID.randomUUID(); String uriStringGroups = "/v1/groups?groupUuid=" + newGroupUuid + "&duplicateFrom=" + TEST_GROUP_ID + "&reportUuid=" + UUID.randomUUID(); mockMvc.perform(post(uriStringGroups)).andExpect(status().isOk()); - - testNetworkModificationsCount(newGroupUuid, 5); + List stashedCopiedModifications = modificationRepository.getModificationsMetadata(newGroupUuid, true); + List copiedModifications = modificationRepository.getModificationsMetadata(newGroupUuid, false); + assertEquals(0, stashedCopiedModifications.size()); + assertEquals(4, copiedModifications.size()); + testNetworkModificationsCount(newGroupUuid, 4); } @Test