Skip to content

Commit

Permalink
save changes
Browse files Browse the repository at this point in the history
Signed-off-by: walid-sahnoun <[email protected]>
  • Loading branch information
Walid-Sahnoun committed Sep 19, 2023
1 parent 68f6a21 commit 9e0daaa
Show file tree
Hide file tree
Showing 3 changed files with 28 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 group")
@ApiResponse(responseCode = "200", description = "Stashed modifications group deleted")
public ResponseEntity<Void> deleteStashedModificationGroup(@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.deleteStashedModificationGroup(groupUuid, errorOnGroupNotFound);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,19 @@ 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 deleteStashedModificationGroup(UUID groupUuid, boolean errorOnGroupNotFound) {
try {
ModificationGroupEntity groupEntity = getModificationGroup(groupUuid);
if (!groupEntity.getModifications().isEmpty()) {
modificationRepository.deleteAll(groupEntity.getModifications().stream().filter(modificationEntity -> modificationEntity.getStashed().equals(true)).collect(Collectors.toList()));
}
} 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 deleteStashedModificationGroup(UUID groupUuid, boolean errorOnGroupNotFound) {
networkModificationRepository.deleteStashedModificationGroup(groupUuid, errorOnGroupNotFound);
}
}

0 comments on commit 9e0daaa

Please sign in to comment.