use of org.mamute.model.Attachment 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 org.mamute.model.Attachment in project mamute by caelum.
the class AttachmentRepositoryTest method should_delete_database_entry.
@Test
public void should_delete_database_entry() {
final Attachment attachment = createAttachment("test");
attachmentRepository.save(attachment);
attachmentRepository.delete(attachment);
assertNull(attachments.load(attachment.getId()));
}
use of org.mamute.model.Attachment in project mamute by caelum.
the class AttachmentRepositoryTest method save_should_create_database_entry.
@Test
public void save_should_create_database_entry() {
final Attachment attachment = createAttachment("test");
attachmentRepository.save(attachment);
assertNotNull(attachment.getId());
assertEquals(attachment, attachments.load(attachment.getId()));
}
use of org.mamute.model.Attachment in project mamute by caelum.
the class ImageStore method processAndStore.
public Attachment processAndStore(UploadedFile avatar, User user, ClientIp clientIp) throws IOException {
BufferedImage resized = processImage(avatar);
Attachment attachment = new Attachment(resized, user, clientIp.get(), avatar.getFileName());
attachments.save(attachment);
fileStorage.saveImage(attachment);
return attachment;
}
use of org.mamute.model.Attachment in project mamute by caelum.
the class AttachmentRepositoryTest method save_should_write_contents_to_disk.
@Test
public void save_should_write_contents_to_disk() throws IOException {
final String fileContents = "hello";
final Attachment attachment = createAttachment(fileContents);
attachmentRepository.save(attachment);
assertEquals(fileContents, IOUtils.toString(fileStorage.open(attachment)));
}
Aggregations