use of org.craftercms.profile.api.services.ProfileAttachment in project profile by craftercms.
the class ProfileServiceImpl method fileInfoToProfileAttachment.
private ProfileAttachment fileInfoToProfileAttachment(final FileInfo fileInfo) {
if (fileInfo == null) {
return new ProfileAttachment();
}
ProfileAttachment attachment = new ProfileAttachment();
attachment.setContentType(fileInfo.getContentType());
;
attachment.setMd5(fileInfo.getMd5());
attachment.setFileName(fileInfo.getStoreName().substring(fileInfo.getStoreName().lastIndexOf("/") + 1));
attachment.setFileSize(fileInfo.getFileSize());
attachment.setFileSizeBytes(fileInfo.getFileSizeBytes());
attachment.setId(fileInfo.getFileId().toString());
return attachment;
}
use of org.craftercms.profile.api.services.ProfileAttachment 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.profile.api.services.ProfileAttachment in project profile by craftercms.
the class ProfileController method getAttachment.
@RequestMapping(value = URL_PROFILE_GET_ATTACHMENT, method = RequestMethod.GET)
@ApiOperation(value = "Gets the requested attachment of the given profile", notes = "If Attachment or profile does not exist will " + "throw error, content-type,content-legnth headers" + " are set")
public void getAttachment(@ApiParam("The profile's ID") @PathVariable(PATH_VAR_ID) String profileId, @ApiParam("Attachment Id to get") @PathVariable(PATH_VAR_ATTACHMENT) String attachmentId, HttpServletResponse response) throws ProfileException, IOException {
Profile profile = profileService.getProfile(profileId);
if (profile != null) {
InputStream input = null;
try {
input = profileService.getProfileAttachment(attachmentId, profile.getId().toString());
if (input != null) {
ProfileAttachment attachment = profileService.getProfileAttachmentInformation(profile.getId().toString(), attachmentId);
response.setContentType(attachment.getContentType());
response.setContentLength((int) attachment.getFileSizeBytes());
IOUtils.copy(input, response.getOutputStream());
}
} catch (ProfileException ex) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
response.setContentLength(0);
} finally {
if (input != null) {
input.close();
}
}
} else {
throw new NoSuchProfileException.ById(profileId);
}
}
Aggregations