class AttachmentFileManager {

    public Attachment uploadAttachment(InputStream attachmentInputStream, String fileName) {
        String systemDataStorageName = preferenceManager.getPreference(
            SystemPreferences.DATA_STORAGE_SYSTEM_DATA_STORAGE_NAME);
        Assert.notNull(systemDataStorageName, messageHelper.getMessage(
            MessageConstants.ERROR_ATTACHMENT_SYSTEM_DATA_STORAGE_NOT_CONFIGURED));

        AbstractDataStorage attachmentStorage = dataStorageManager.loadByNameOrId(systemDataStorageName);

        UUID uuid = UUID.randomUUID();
        String uniqueName = uuid.toString() + "-" + fileName;
        DataStorageFile uploadedFile = dataStorageManager.createDataStorageFile(attachmentStorage.getId(),
                                                                                ATTACHMENTS_DIRECTORY, uniqueName,
                                                                                attachmentInputStream);
        Attachment attachment = new Attachment();
        attachment.setPath(uploadedFile.getPath());
        attachment.setName(fileName);
        attachment.setCreatedDate(DateUtils.now());
        attachment.setOwner(authManager.getAuthorizedUser());

        attachmentManager.create(attachment);
        return attachment;
    }

    @Autowired public  AttachmentFileManager(DataStorageManager dataStorageManager, PreferenceManager preferenceManager,
                                 AttachmentManager attachmentManager, MessageHelper messageHelper,
                                 AuthManager authManager);

}