Skip to content
Closed
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 @@ -456,7 +456,8 @@ public void deleteAllStashedElements(UUID studyId) {
List<UUID> notStashedModificationGroupUuids = networkModificationNodeInfos.stream()
.map(NetworkModificationNodeInfoEntity::getModificationGroupUuid)
.toList();
networkModificationService.deleteStashedModificationsFromGroups(notStashedModificationGroupUuids, SUPERVISION_USER);
// the links of the remaining reference modifications to their shared modifications are kept
networkModificationService.deleteStashedModificationsFromGroups(notStashedModificationGroupUuids, false, SUPERVISION_USER);

// remove stashed nodes and their modifications
studyService.deleteNodes(studyId, stashedNodes.stream().map(NodeEntity::getIdNode).toList(), true, SUPERVISION_USER, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,10 @@ private String toJson(Object object) {
}

public void deleteStashedModificationsFromGroups(List<UUID> groupUuids, String userId) {
deleteStashedModificationsFromGroups(groupUuids, true, userId);
}

public void deleteStashedModificationsFromGroups(List<UUID> groupUuids, boolean removeElementReferences, String userId) {
Objects.requireNonNull(groupUuids);
if (groupUuids.isEmpty()) {
return;
Expand All @@ -659,8 +663,11 @@ public void deleteStashedModificationsFromGroups(List<UUID> groupUuids, String u
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set(HEADER_USER_ID, userId);
HttpEntity<String> httpEntity = new HttpEntity<>(toJson(groupUuids), headers);
var path = UriComponentsBuilder.fromPath(GROUPS + "/stashed-modifications")
.toUriString();
var uriBuilder = UriComponentsBuilder.fromPath(GROUPS + "/stashed-modifications");
if (!removeElementReferences) {
uriBuilder.queryParam("removeElementReferences", false);
}
var path = uriBuilder.toUriString();

restTemplate.exchange(getNetworkModificationServerURI(false) + path,
HttpMethod.DELETE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ void testDeleteStashedModificationsGroups() {
verify(restTemplate).exchange(expectedUrl, HttpMethod.DELETE, httpEntity, new ParameterizedTypeReference<Map<UUID, UUID>>() { });
}

@Test
void testDeleteStashedModificationsGroupsKeepingElementReferences() {
UUID groupUuid = UUID.randomUUID();
String expectedUrl = NETWORK_MODIFICATION_SERVER_URI + "/v1/groups/stashed-modifications?removeElementReferences=false";

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set(HEADER_USER_ID, USER_ID);
networkModificationService.deleteStashedModificationsFromGroups(List.of(groupUuid), false, USER_ID);
HttpEntity<String> httpEntity = new HttpEntity<>("[\"" + groupUuid + "\"]", headers);
verify(restTemplate).exchange(expectedUrl, HttpMethod.DELETE, httpEntity, new ParameterizedTypeReference<Map<UUID, UUID>>() { });
}

@Test
void testGetReferences() {
UUID firstUuid = UUID.randomUUID();
Expand Down
Loading