private FileAttachment makeAttachment(MultipartFile sourceFile, String relativeDir, File targetFile, AttachmentCategory category) throws IOException { FileAttachment attachment = new FileAttachment(); attachment.setFilename(sourceFile.getOriginalFilename()); attachment.setPath(relativeDir + File.separator + targetFile.getName()); attachment.setCategory(category); attachment.setCreator(authorizationManager.getCurrentUser()); attachment.setCreationTime(new Date()); return attachment; }