Search in sources :

Example 1 with DefaultUploadedFile

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultUploadedFile(br.com.caelum.vraptor.observer.upload.DefaultUploadedFile) Attachment(org.mamute.model.Attachment) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 2 with DefaultUploadedFile

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;
}
Also used : User(org.mamute.model.User) UploadedFile(br.com.caelum.vraptor.observer.upload.UploadedFile) DefaultUploadedFile(br.com.caelum.vraptor.observer.upload.DefaultUploadedFile) DefaultUploadedFile(br.com.caelum.vraptor.observer.upload.DefaultUploadedFile) Attachment(org.mamute.model.Attachment)

Aggregations

DefaultUploadedFile (br.com.caelum.vraptor.observer.upload.DefaultUploadedFile)2 Attachment (org.mamute.model.Attachment)2 UploadedFile (br.com.caelum.vraptor.observer.upload.UploadedFile)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 User (org.mamute.model.User)1