use of com.ncedu.fooddelivery.api.v1.errors.badrequest.FileDeleteException in project 2021-msk-food-delivery by netcracker-edu.
the class FileServiceImpl method delete.
@Override
public void delete(File file, User authedUser) {
boolean isAdminOrOwner = checkAdminOrOwner(file, authedUser);
if (!isAdminOrOwner) {
log.error(authedUser.getEmail() + " not Admin and not Owner of the file " + file.getId().toString());
throw new CustomAccessDeniedException();
}
try {
fileRepo.delete(file);
Path fullFilePath = createFullPathToFile(file.getId());
Files.deleteIfExists(fullFilePath);
Path fileParentDirPath = fullFilePath.getParent();
log.debug("PARENT DIR PATH: " + fileParentDirPath + "\n");
boolean isParentDirEmpty = checkParentDirEmpty(fileParentDirPath);
if (isParentDirEmpty) {
Files.delete(fileParentDirPath);
}
} catch (IOException e) {
throw new FileDeleteException();
}
}
Aggregations