Advertisement
Coriic

Untitled

Jan 18th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. public FileMetadata handleRename(Request request, Response response){
  2.         try{
  3.             PathManager pathManager = new PathManager(request.params(":path"));
  4.             String name = request.params(":name");
  5.             if(!(fileMetadataRepository.fetchByPathDisplay(pathManager.getPath()).isEmpty())){
  6.                 if(sessionDataRepository.fetchBySessionId(request.params(":session")).get(0).getUserId()
  7.                         .equals(fileMetadataRepository.fetchByFolderPath(pathManager.getPath()).get(0).getOwnerId())){
  8.                     fileMetadataRepository.updateServerChangedAt(LocalDateTime.now().format(DateTimeFormatter.ofPattern("%Y-%m-%dT%H:%M:%SZ")),
  9.                             pathManager.getPath());
  10.                     response.status(SUCCESSFULOPERATION);
  11.                     return fileMetadataRepository.changeNameByPath(pathManager.getPath(), name);
  12.                 }
  13.                 else{
  14.                     response.status(UNSUCCESSFULAUTHORIZATION);
  15.                     throw new UnsuccessfulAuthorization("Unsuccessful authorization");
  16.                 }
  17.             }
  18.             else{
  19.                 response.status(FILEDOESNOTEXIST);
  20.                 throw new FileDoesNotExist("File with path: " + pathManager.getPath() + " already exists");
  21.             }
  22.  
  23.         }
  24.         catch(WrongPathFormat ex){
  25.             response.status(INVALIDPATHPARAMETER);
  26.             throw ex;
  27.         }
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement