Skip to content

Commit

Permalink
delete_stashed_modifications_when_stash_node_or_subtree (#331)
Browse files Browse the repository at this point in the history
delete_stashed_modification_when_stash_node_or_subtree
Signed-off-by: walid-sahnoun <[email protected]>
  • Loading branch information
Walid-Sahnoun authored Sep 20, 2023
1 parent 1e81bc8 commit 1f9f70e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,13 @@ public ResponseEntity<Optional<NetworkModificationResult>> duplicateModification
@Parameter(description = "origin group UUID, from where modifications are copied") @RequestParam(value = "duplicateFrom") UUID originGroupUuid) {
return ResponseEntity.ok().body(networkModificationService.duplicateModificationsInGroup(targetGroupUuid, networkUuid, variantId, new ReportInfos(reportUuid, reporterId.toString()), originGroupUuid));
}

@DeleteMapping(value = "/groups/{groupUuid}/stashed-modifications")
@Operation(summary = "Delete the stashed modifications in a group")
@ApiResponse(responseCode = "200", description = "Stashed modifications in the group deleted")
public ResponseEntity<Void> deleteStashedModificationInGroup(@Parameter(description = "Group UUID") @PathVariable("groupUuid") UUID groupUuid,
@Parameter(description = "Return 404 if group is not found") @RequestParam(name = "errorOnGroupNotFound", required = false, defaultValue = "true") Boolean errorOnGroupNotFound) {
networkModificationService.deleteStashedModificationInGroup(groupUuid, errorOnGroupNotFound);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,21 @@ public void updateModification(@NonNull UUID modificationUuid, @NonNull Modifica
.orElseThrow(() -> new NetworkModificationException(MODIFICATION_NOT_FOUND, String.format(MODIFICATION_NOT_FOUND_MESSAGE, modificationUuid)))
.update(modificationInfos);
}

@Transactional
public void deleteStashedModificationInGroup(UUID groupUuid, boolean errorOnGroupNotFound) {
try {
ModificationGroupEntity groupEntity = getModificationGroup(groupUuid);
if (!groupEntity.getModifications().isEmpty()) {
List<UUID> stashedModifications = groupEntity.getModifications().stream()
.filter(ModificationEntity::getStashed).map(ModificationEntity::getId).collect(Collectors.toList());
deleteModifications(groupUuid, stashedModifications);
}
} catch (NetworkModificationException e) {
if (e.getType() == MODIFICATION_GROUP_NOT_FOUND && !errorOnGroupNotFound) {
return;
}
throw e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,8 @@ public Optional<NetworkModificationResult> duplicateModificationsInGroup(UUID ta
List<ModificationEntity> duplicatedModificationsEntities = networkModificationRepository.copyModificationsEntities(originGroupUuid);
return saveAndApplyModifications(targetGroupUuid, networkUuid, variantId, reportInfos, duplicatedModificationsEntities);
}

public void deleteStashedModificationInGroup(UUID groupUuid, boolean errorOnGroupNotFound) {
networkModificationRepository.deleteStashedModificationInGroup(groupUuid, errorOnGroupNotFound);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1295,4 +1295,30 @@ public void testCreateVoltageInitModification() throws Exception {
assertEquals(1, modificationsInfos2.size());
assertThat(modificationsInfos2.get(0)).recursivelyEquals(modificationsInfos1);
}

@Test
public void testDeleteStashedNetworkModifications() throws Exception {
MvcResult mvcResult;
EquipmentAttributeModificationInfos loadModificationInfos = EquipmentAttributeModificationInfos.builder()
.equipmentType(IdentifiableType.LOAD)
.equipmentAttributeName("v1load")
.equipmentId("v1load")
.build();
String loadModificationInfosJson = objectWriter.writeValueAsString(loadModificationInfos);

mvcResult = mockMvc.perform(post(URI_NETWORK_MODIF).content(loadModificationInfosJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn();
assertApplicationStatusOK(mvcResult);

List<ModificationInfos> modifications = modificationRepository.getModifications(TEST_GROUP_ID, false, true);
assertEquals(1, modifications.size());
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());
assertEquals(1, modificationRepository.getModifications(TEST_GROUP_ID, false, true, true).size());
mockMvc.perform(delete("/v1/groups/" + TEST_GROUP_ID + "/stashed-modifications").queryParam("errorOnGroupNotFound", "false")).andExpect(status().isOk());
assertEquals(0, modificationRepository.getModifications(TEST_GROUP_ID, false, true, true).size());
mockMvc.perform(delete("/v1/groups/" + UUID.randomUUID() + "/stashed-modifications").queryParam("errorOnGroupNotFound", "false")).andExpect(status().isOk());
}
}

0 comments on commit 1f9f70e

Please sign in to comment.