use of br.com.caelum.vraptor.observer.upload.DefaultUploadedFile in project mamute by caelum.
the class LDAPApi method updateAvatarImage.
private void updateAvatarImage(LDAPResource ldap, Entry entry, User user) {
try {
byte[] jpegBytes = getAvatarImage(ldap, entry);
if (jpegBytes != null) {
String fileName = user.getEmail() + ".jpg";
DefaultUploadedFile avatar = new DefaultUploadedFile(new ByteArrayInputStream(jpegBytes), fileName, "image/jpeg", jpegBytes.length);
Attachment attachment = imageStore.processAndStore(avatar, user, clientIp);
Attachment old = user.getAvatar();
if (old != null) {
imageStore.delete(old);
}
user.setAvatar(attachment);
}
} catch (LdapException | IOException e) {
// problems with avatar processing are non-fatal
logger.warn("Error updating user avatar from LDAP: " + user.getName(), e);
}
}
use of br.com.caelum.vraptor.observer.upload.DefaultUploadedFile in project mamute by caelum.
the class AttachmentRepositoryTest method createAttachment.
private Attachment createAttachment(final String content) {
final User owner = user("attachment owner", "attachment@owner.local");
session.save(owner);
final UploadedFile file = new DefaultUploadedFile(IOUtils.toInputStream(content), "hello.txt", "text/plain", content.length());
final Attachment attachment = new Attachment(file, owner, "127.0.0.1");
return attachment;
}
Aggregations