Advertisement
Coriic

Untitled

Jan 18th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. public void handleDeleteFolder(Request request, Response response){
  2.         try{
  3.             PathManager path = new PathManager(request.params(":path"));
  4.             if(!(sessionDataRepository.fetchBySessionId(request.params(":session")).get(0).getUserId()
  5.                     .equals(fileMetadataRepository.fetchByFolderPath(path.getPath()).get(0).getOwnerId()))) {
  6.                 response.status(UNSUCCESSFULAUTHORIZATION);
  7.                 throw new UnsuccessfulAuthorization("Unsuccessful authorization");
  8.             }
  9.             if(folderMetadataRepostiory.fetchByPathDisplay(path.getPath()).isEmpty()) {
  10.                 response.status(FOLDERDOESNOTEXIST);
  11.                 throw new FileDoesNotExist("Folder with path: " + path.getPath() + " already exists");
  12.             }
  13.             folderMetadataRepostiory.deleteFoldersByPath(path.getPath());
  14.             fileContentsRepository.deleteById(fileMetadataRepository.getFileIdFromPath(path.getPath()));
  15.             fileMetadataRepository.deleteFromSpecifiedPath(path.getPath());
  16.             response.status(DELETED);
  17.         }
  18.         catch(WrongPathFormat ex){
  19.             response.status(INVALIDPATHPARAMETER);
  20.             throw ex;
  21.         }
  22.         catch(RuntimeException ex){
  23.             throw ex;
  24.         }
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement