Package eu.semberal.reminders.entity

Examples of eu.semberal.reminders.entity.Attachment


    }

    public Resolution download() {

        if (attachmentId == null) return new ErrorResolution(404);
        Attachment attachment = filesService.getAttachment(attachmentId);
        if (attachment == null || !attachment.getUser().equals(getContext().getUser())) return new ErrorResolution(403);
        File f = filesService.getAttachmentFile(attachmentId);
        if (f == null || attachment == null) return new ErrorResolution(404);

        FileInputStream fileInputStream;
        try {
            fileInputStream = new FileInputStream(f);
        } catch (Exception e) {
            return new ErrorResolution(404);
        }
        return new StreamingResolution(null, fileInputStream).setFilename(attachment.getFilename());
    }
View Full Code Here


    }


    public Resolution delete() {
        if (attachmentId == null) return new ErrorResolution(404);
        Attachment a = filesService.getAttachment(attachmentId);
        if (a == null || !a.getUser().equals(getContext().getUser())) return new ErrorResolution(403);

        filesService.deleteAttachment(attachmentId);
        getContext().getMessages().add(new LocalizableMessage("eu.semberal.reminders.stripes.action.secure.FilesListActionBean.fileDeleted", a.getFilename()));
        return new RedirectResolution(FilesListActionBean.class);
    }
View Full Code Here

            throw new IllegalArgumentException("Argument is null"); //if sth is null, throw exception
        User u = entityManager.find(User.class, userId);
        if (u == null)
            throw new IllegalArgumentException("User with specified ID was not found."); //if user not found, throw error

        Attachment a = new Attachment();
        a.setDateAdded(new Date());
        a.setUser(u);
        a.setFilename(filename);
        a.setSize(0L);
        entityManager.persist(a);
        entityManager.flush(); //if the file was successfully put into the database, continue with saving the file on the disc
        File f = new File(computePath(a));
        f.getParentFile().mkdirs();
        long bytes = FileCopyUtils.copy(new BufferedInputStream(stream), new BufferedOutputStream(new FileOutputStream(f)));
        a.setSize(bytes);
    }
View Full Code Here

        return entityManager.find(Attachment.class, id);
    }

    @Override
    public File getAttachmentFile(Long id) {
        Attachment a = entityManager.find(Attachment.class, id);
        if (a == null) return null;
        File f = new File(computePath(a));
        if (!f.exists() || !f.canRead() || !f.isFile()) {
            log.error("File {} was found in database as attachment, but is not readable on filesystem", f.getAbsolutePath());
            return null;
View Full Code Here

    }

    @Override
    @SuppressWarnings("unchecked")
    public void deleteAttachment(Long id) {
        Attachment a = entityManager.find(Attachment.class, id);
        if (a == null) return;
        File f = new File(computePath(a));

        Query q = entityManager.createQuery("select n from Note n where :a member of n.attachments");
        q.setParameter("a", a);
View Full Code Here

TOP

Related Classes of eu.semberal.reminders.entity.Attachment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.