Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy node and duplicate not stashed modifications #320

Merged
merged 5 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public List<ModificationInfos> getModifications(UUID groupUuid, boolean onlyMeta
}
}

private List<ModificationInfos> getModificationsMetadata(UUID groupUuid, boolean stashedModifications) {
public List<ModificationInfos> getModificationsMetadata(UUID groupUuid, boolean stashedModifications) {
return modificationRepository
.findAllBaseByGroupId(getModificationGroup(groupUuid).getId())
.stream()
Expand Down Expand Up @@ -206,7 +206,7 @@ public List<ModificationEntity> getModificationsEntities(@NonNull List<UUID> uui

@Transactional(readOnly = true)
public List<ModificationEntity> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,12 +756,30 @@ public void testDuplicateModificationGroup() throws Exception {
assertApplicationStatusOK(mvcResult);
testNetworkModificationsCount(TEST_GROUP_ID, 5);

//test copy group
// get list of modifications
List<ModificationInfos> 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<ModificationInfos> stashedModifications = modificationRepository.getModificationsMetadata(TEST_GROUP_ID, true);
List<ModificationInfos> 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<ModificationInfos> stashedCopiedModifications = modificationRepository.getModificationsMetadata(newGroupUuid, true);
List<ModificationInfos> copiedModifications = modificationRepository.getModificationsMetadata(newGroupUuid, false);
assertEquals(0, stashedCopiedModifications.size());
assertEquals(4, copiedModifications.size());
testNetworkModificationsCount(newGroupUuid, 4);
}

@Test
Expand Down