Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public FileMetadata handleRename(Request request, Response response){
- try{
- PathManager pathManager = new PathManager(request.params(":path"));
- String name = request.params(":name");
- if(!(fileMetadataRepository.fetchByPathDisplay(pathManager.getPath()).isEmpty())){
- if(sessionDataRepository.fetchBySessionId(request.params(":session")).get(0).getUserId()
- .equals(fileMetadataRepository.fetchByFolderPath(pathManager.getPath()).get(0).getOwnerId())){
- fileMetadataRepository.updateServerChangedAt(LocalDateTime.now().format(DateTimeFormatter.ofPattern("%Y-%m-%dT%H:%M:%SZ")),
- pathManager.getPath());
- response.status(SUCCESSFULOPERATION);
- return fileMetadataRepository.changeNameByPath(pathManager.getPath(), name);
- }
- else{
- response.status(UNSUCCESSFULAUTHORIZATION);
- throw new UnsuccessfulAuthorization("Unsuccessful authorization");
- }
- }
- else{
- response.status(FILEDOESNOTEXIST);
- throw new FileDoesNotExist("File with path: " + pathManager.getPath() + " already exists");
- }
- }
- catch(WrongPathFormat ex){
- response.status(INVALIDPATHPARAMETER);
- throw ex;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement