use of org.craftercms.commons.mongo.FileInfo in project profile by craftercms.
the class ProfileServiceImpl method getProfileAttachments.
@Override
public List<ProfileAttachment> getProfileAttachments(final String profileId) throws ProfileException {
List<FileInfo> files = profileRepository.listFilesByName(profileId);
List<ProfileAttachment> attachments = new ArrayList<>();
for (FileInfo file : files) {
attachments.add(fileInfoToProfileAttachment(file));
}
return attachments;
}
use of org.craftercms.commons.mongo.FileInfo in project profile by craftercms.
the class ProfileServiceImpl method addProfileAttachment.
@Override
public ProfileAttachment addProfileAttachment(final String profileId, final String attachmentName, final InputStream file) throws ProfileException {
String storeName = "/" + profileId + "/" + FilenameUtils.removeExtension(attachmentName);
try {
ObjectId currentId = checkIfAttachmentExist(storeName);
String mimeType = getAttachmentContentType(attachmentName);
FileInfo fileInfo;
if (currentId != null) {
// Update !!!
fileInfo = profileRepository.updateFile(currentId, file, storeName, mimeType, true);
} else {
fileInfo = profileRepository.saveFile(file, storeName, mimeType);
}
return fileInfoToProfileAttachment(fileInfo);
} catch (MongoDataException | FileExistsException | FileNotFoundException e) {
throw new ProfileException("Unable to attach file to profile '" + profileId + "'", e);
}
}
Aggregations