Skip to content

Commit

Permalink
Copy node and duplicate not stashed modifications (#320)
Browse files Browse the repository at this point in the history
* copy node and duplicate not stashed modifications
---------

Signed-off-by: Maissa SOUISSI <[email protected]>
  • Loading branch information
souissimai authored Sep 7, 2023
1 parent a251ca5 commit a8e9318
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
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

0 comments on commit a8e9318

Please sign in to comment.