Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -44,7 +44,8 @@ public class NetworkModificationService {

private static final String DELIMITER = "/";
private static final String COMPOSITE_PATH = "network-composite-modifications" + DELIMITER;
private static final String GROUP_PATH = "groups" + DELIMITER + "{groupUuid}";
private static final String GROUPS = "groups";
private static final String GROUP_PATH = GROUPS + DELIMITER + "{groupUuid}";
private static final String CONTAINER_PATH = "containers" + DELIMITER + "{containerId}";
private static final String NETWORK_MODIFICATIONS_PATH = "network-modifications";
private static final String NETWORK_MODIFICATIONS_COUNT_PATH = "network-modifications-count";
Expand Down Expand Up @@ -178,6 +179,24 @@ public void deleteModifications(UUID groupUUid) {
restTemplate.delete(getNetworkModificationServerURI(false) + path);
}

public void deleteModificationsGroups(List<UUID> groupUuids) {
Objects.requireNonNull(groupUuids);
if (groupUuids.isEmpty()) {
return;
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> httpEntity = new HttpEntity<>(toJson(groupUuids), headers);
var path = UriComponentsBuilder.fromPath(GROUPS)
.queryParam(QUERY_PARAM_ERROR_ON_GROUP_NOT_FOUND, false)
.toUriString();

restTemplate.exchange(getNetworkModificationServerURI(false) + path,
HttpMethod.DELETE,
httpEntity,
new ParameterizedTypeReference<Map<UUID, UUID>>() { });
}

public void deleteModifications(UUID groupUuid, List<UUID> modificationsUuids) {
Objects.requireNonNull(groupUuid);
var path = UriComponentsBuilder
Expand Down Expand Up @@ -487,6 +506,24 @@ private String toJson(Object object) {
return json;
}

public void deleteStashedModificationsGroups(List<UUID> groupUuids) {
Objects.requireNonNull(groupUuids);
if (groupUuids.isEmpty()) {
return;
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> httpEntity = new HttpEntity<>(toJson(groupUuids), headers);
var path = UriComponentsBuilder.fromPath(GROUPS + "/stashed-modifications")
.queryParam(QUERY_PARAM_ERROR_ON_GROUP_NOT_FOUND, false)
.toUriString();

restTemplate.exchange(getNetworkModificationServerURI(false) + path,
HttpMethod.DELETE,
httpEntity,
new ParameterizedTypeReference<Map<UUID, UUID>>() { });
}

public void deleteStashedModifications(UUID groupUUid) {
Objects.requireNonNull(groupUUid);
var path = UriComponentsBuilder.fromPath(GROUP_PATH + "/stashed-modifications")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,41 @@ public void doDeleteTree(UUID studyId) {
}
}

@Transactional
public void deleteAllStashedElements(UUID studyId) {
List<NodeEntity> nodes = nodesRepository.findAllByStudyId(studyId);
List<NodeEntity> stashedNodes = new ArrayList<>();
List<NodeEntity> notStashedNodes = new ArrayList<>();
for (NodeEntity nodeEntity : nodes) {
if (nodeEntity.isStashed()) {
stashedNodes.add(nodeEntity);
} else {
notStashedNodes.add(nodeEntity);
}
}

// remove stashed modification on not stashed nodes
List<NetworkModificationNode> networkModificationNodeInfos = networkModificationNodeInfoRepository
.findAllById(notStashedNodes.stream().map(NodeEntity::getIdNode).toList())
.stream().map(NetworkModificationNodeInfoEntity::toDto).toList();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to pass throught the DTO, this is strange, NetworkModificationNodeInfoEntity already has the modificationGroupUuid member

List<UUID> stashedModificationGroupUuids = networkModificationNodeInfos.stream()
.map(NetworkModificationNode::getModificationGroupUuid)
.toList();
networkModificationService.deleteStashedModificationsGroups(stashedModificationGroupUuids);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does a stashed modification exists in a group which contain a non stashed modification in a non stashed node ?
I see that when we stash a node, we call deleteStashedModifications. it's not clear for me i will investigate.


// remove modification on stashed nodes
List<NetworkModificationNode> networkModificationNodeInfosToDelete = networkModificationNodeInfoRepository
.findAllById(stashedNodes.stream().map(NodeEntity::getIdNode).toList())
.stream().map(NetworkModificationNodeInfoEntity::toDto).toList();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same remark here

List<UUID> modificationGroupUuidsToDelete = networkModificationNodeInfosToDelete.stream()
.map(NetworkModificationNode::getModificationGroupUuid)
.toList();
networkModificationService.deleteModificationsGroups(modificationGroupUuidsToDelete);
// remove stashed nodes
networkModificationNodeInfoRepository.deleteAllById(stashedNodes.stream().map(NodeEntity::getIdNode).toList());
nodesRepository.deleteAll(stashedNodes);
}

@Transactional
public NodeEntity createRoot(StudyEntity study) {
NodeEntity node = nodesRepository.save(new NodeEntity(null, null, NodeType.ROOT, study, false, null, new ArrayList<>()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ public void invalidateStudy(UUID studyUuid) {
AtomicReference<Long> startTime = new AtomicReference<>();
startTime.set(System.nanoTime());
try {
// remove all stashed nodes and network modifications
networkModificationTreeService.deleteAllStashedElements(studyUuid);
rootNetworkService.getStudyRootNetworkIds(studyUuid).forEach(rnId ->
studyService.invalidateStudyRootNetwork(studyUuid, rnId, SUPERVISION_USER)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -122,4 +126,30 @@ void testUpdateNetworkModificationsMetadata() {

verify(restTemplate).exchange(eq(expectedUrl), eq(HttpMethod.PUT), org.mockito.ArgumentMatchers.<HttpEntity<String>>any(), eq(Void.class));
}

@Test
void testDeleteModificationsGroups() {
UUID firstUuid = UUID.randomUUID();
UUID secondUuid = UUID.randomUUID();
String expectedUrl = NETWORK_MODIFICATION_SERVER_URI + "/v1/groups?errorOnGroupNotFound=false";

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

@Test
void testDeleteStashedModificationsGroups() {
UUID firstUuid = UUID.randomUUID();
UUID secondUuid = UUID.randomUUID();
String expectedUrl = NETWORK_MODIFICATION_SERVER_URI + "/v1/groups/stashed-modifications?errorOnGroupNotFound=false";

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
networkModificationService.deleteStashedModificationsGroups(List.of(firstUuid, secondUuid));
HttpEntity<String> httpEntity = new HttpEntity<>("[\"" + firstUuid + "\",\"" + secondUuid + "\"]", headers);
verify(restTemplate).exchange(expectedUrl, HttpMethod.DELETE, httpEntity, new ParameterizedTypeReference<Map<UUID, UUID>>() { });
}
}
Loading