Package fr.ippon.tatami.domain

Examples of fr.ippon.tatami.domain.Attachment


            method = RequestMethod.DELETE,
            produces = "application/json")
    @ResponseBody
    @Timed
    public Attachment DeleteAttachment(@PathVariable("attachmentId") String attachmentId) {
        Attachment attachment = attachmentService.getAttachmentById(attachmentId);
        attachmentService.deleteAttachment(attachment);
        return attachment;
    }
View Full Code Here


        userRepository.updateUser(currentUser);
        return attachment.getAttachmentId();
    }

    public Attachment getAttachmentById(String attachmentId) {
        Attachment attachment =  attachmentRepository.findAttachmentById(attachmentId);
        //Computing the thumbnail if it does not exists
        if(! attachment.getHasThumbnail()) {
          attachment.setThumbnail(computeThumbnail(attachment));
          attachmentRepository.updateThumbnail(attachment);
        }
        return attachment;
    }
View Full Code Here

        status.setDetailsAvailable(computeDetailsAvailable(status));
        if (status.getHasAttachments() != null && status.getHasAttachments()) {
            Collection<String> attachmentIds = statusAttachmentRepository.findAttachmentIds(statusId);
            Collection<Attachment> attachments = new ArrayList<Attachment>();
            for (String attachmentId : attachmentIds) {
                Attachment attachment = attachmentRepository.findAttachmentMetadataById(attachmentId);
                if (attachment != null) {
                    // We copy everything excepted the attachment content, as we do not want it in the status cache
                    Attachment attachmentCopy = new Attachment();
                    attachmentCopy.setAttachmentId(attachmentId);
                    attachmentCopy.setSize(attachment.getSize());
                    attachmentCopy.setFilename(attachment.getFilename());
                    attachments.add(attachment);
                }
            }
            status.setAttachments(attachments);
        }
View Full Code Here

            return null;
        }

        log.debug("Finding attachment : {}", attachmentId);

        Attachment attachment = this.findAttachmentMetadataById(attachmentId);

        if (attachment == null) {
            return null;
        }

        ColumnQuery<String, String, byte[]> queryAttachment = HFactory.createColumnQuery(keyspaceOperator,
                StringSerializer.get(), StringSerializer.get(), BytesArraySerializer.get());

        HColumn<String, byte[]> columnAttachment =
                queryAttachment.setColumnFamily(ATTACHMENT_CF)
                        .setKey(attachmentId)
                        .setName(CONTENT)
                        .execute()
                        .get();

        attachment.setContent(columnAttachment.getValue());
       
        ColumnQuery<String, String, byte[]> queryThumbnail = HFactory.createColumnQuery(keyspaceOperator,
            StringSerializer.get(), StringSerializer.get(), BytesArraySerializer.get());
       
        HColumn<String, byte[]> columnThumbnail =
            queryThumbnail.setColumnFamily(ATTACHMENT_CF)
                .setKey(attachmentId)
                .setName(THUMBNAIL)
                .execute()
                .get();
        if(columnThumbnail != null && columnThumbnail.getValue().length > 0) {
          attachment.setThumbnail(columnThumbnail.getValue());
          attachment.setHasThumbnail(true);
        }
        else {
          attachment.setHasThumbnail(false);
        }
        return attachment;
    }
View Full Code Here

    @Override
    public Attachment findAttachmentMetadataById(String attachmentId) {
        if (attachmentId == null) {
            return null;
        }
        Attachment attachment = new Attachment();
        attachment.setAttachmentId(attachmentId);

        ColumnQuery<String, String, String> queryFilename = HFactory.createColumnQuery(keyspaceOperator,
                StringSerializer.get(), StringSerializer.get(), StringSerializer.get());

        HColumn<String, String> columnFilename =
                queryFilename.setColumnFamily(ATTACHMENT_CF)
                        .setKey(attachmentId)
                        .setName(FILENAME)
                        .execute()
                        .get();

        if (columnFilename != null && columnFilename.getValue() != null) {
            attachment.setFilename(columnFilename.getValue());
        } else {
            return null;
        }

        ColumnQuery<String, String, Long> querySize = HFactory.createColumnQuery(keyspaceOperator,
                StringSerializer.get(), StringSerializer.get(), LongSerializer.get());

        HColumn<String, Long> columnSize =
                querySize.setColumnFamily(ATTACHMENT_CF)
                        .setKey(attachmentId)
                        .setName(SIZE)
                        .execute()
                        .get();

        if (columnSize != null && columnSize.getValue() != null) {
            attachment.setSize(columnSize.getValue());
        } else {
            return null;
        }

        ColumnQuery<String, String, Date> queryCreationDate = HFactory.createColumnQuery(keyspaceOperator,
                StringSerializer.get(), StringSerializer.get(), DateSerializer.get());

        HColumn<String, Date> columnCreationDate =
                queryCreationDate.setColumnFamily(ATTACHMENT_CF)
                        .setKey(attachmentId)
                        .setName(CREATION_DATE)
                        .execute()
                        .get();

        if (columnCreationDate != null && columnCreationDate.getValue() != null) {
            attachment.setCreationDate(columnCreationDate.getValue());
        } else {
            attachment.setCreationDate(new Date());
        }

        return attachment;
    }
View Full Code Here

        // Cache the file in the browser
        response.setDateHeader(HEADER_EXPIRES, System.currentTimeMillis() + CACHE_SECONDS * 1000L);
        response.setHeader(HEADER_CACHE_CONTROL, "max-age=" + CACHE_SECONDS + ", must-revalidate");

        // Put the file in the response
        Attachment attachment = attachmentService.getAttachmentById(attachmentId);
        if (attachment == null) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            response.sendRedirect("/tatami/file/file_not_found");
        } else {
            // ETag support
            response.setHeader(HEADER_ETAG, attachmentId); // The attachmentId is unique and should not be modified
            String requestETag = request.getHeader(HEADER_IF_NONE_MATCH);
            if (requestETag != null && requestETag.equals(attachmentId)) {
                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            } else {
                try {
                    byte[] fileContent = attachment.getContent();
                    response.getOutputStream().write(fileContent);
                } catch (IOException e) {
                    log.info("Error writing file to output stream. {}", e.getMessage());
                }
            }
View Full Code Here

      // Cache the file in the browser
        response.setDateHeader(HEADER_EXPIRES, System.currentTimeMillis() + CACHE_SECONDS * 1000L);
        response.setHeader(HEADER_CACHE_CONTROL, "max-age=" + CACHE_SECONDS + ", must-revalidate");

        // Put the file in the response
        Attachment attachment = attachmentService.getAttachmentById(attachmentId);
        if (attachment == null || attachment.getThumbnail().length == 0) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            response.sendRedirect("/tatami/file/file_not_found");
        } else {
            // ETag support
            response.setHeader(HEADER_ETAG, attachmentId); // The attachmentId is unique and should not be modified
            String requestETag = request.getHeader(HEADER_IF_NONE_MATCH);
            if (requestETag != null && requestETag.equals(attachmentId)) {
                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            } else {
                try {
                    byte[] fileContent = attachment.getThumbnail();
                    response.getOutputStream().write(fileContent);
                } catch (IOException e) {
                    log.info("Error writing file to output stream. {}", e.getMessage());
                }
            }
View Full Code Here

    @ResponseBody
    @Timed
    public List<UploadedFile> upload(@RequestParam("uploadFile") MultipartFile file)
            throws IOException, StorageSizeException {

        Attachment attachment = new Attachment();
        attachment.setContent(file.getBytes());
        attachment.setFilename(file.getName());
        attachment.setSize(file.getSize());
        attachment.setFilename(file.getOriginalFilename());
        attachment.setCreationDate(new Date());

        attachmentService.createAttachment(attachment);

        log.debug("Created attachment : {}", attachment.getAttachmentId());

        List<UploadedFile> uploadedFiles = new ArrayList<UploadedFile>();
        UploadedFile uploadedFile = new UploadedFile(
                attachment.getAttachmentId(),
                file.getOriginalFilename(),
                Long.valueOf(file.getSize()).intValue(),
                tatamiUrl + "/tatami/file/" + attachment.getAttachmentId() + "/" + file.getOriginalFilename());

        uploadedFiles.add(uploadedFile);
        return uploadedFiles;
    }
View Full Code Here

    @ResponseBody
    @Timed
    public String uploadIE(@RequestParam("uploadFile") MultipartFile file)
            throws IOException, StorageSizeException {

        Attachment attachment = new Attachment();
        attachment.setContent(file.getBytes());
        attachment.setFilename(file.getName());
        attachment.setSize(file.getSize());
        attachment.setFilename(file.getOriginalFilename());
        attachment.setCreationDate(new Date());

        attachmentService.createAttachment(attachment);

        log.debug("Created attachment : {}", attachment.getAttachmentId());
       
        String result = attachment.getAttachmentId()+":::"+file.getOriginalFilename()+":::"+file.getSize();
       
        return URLEncoder.encode(result, "UTF-8");
   
    }
View Full Code Here

TOP

Related Classes of fr.ippon.tatami.domain.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.