Package fr.ippon.tatami.domain

Examples of fr.ippon.tatami.domain.Avatar


        if (avatarId == null) {
            return null;
        }
        log.debug("Finding avatar : {}", avatarId);

        Avatar avatar = this.findAttachmentMetadataById(avatarId);

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

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

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

        avatar.setContent(columnAttachment.getValue());
        return avatar;
    }
View Full Code Here


    Avatar findAttachmentMetadataById(String avatarId) {
        if (avatarId == null) {
            return null;
        }
        Avatar avatar = new Avatar();
        avatar.setAvatarId(avatarId);

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

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

        if (columnFilename != null && columnFilename.getValue() != null) {
            avatar.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(AVATAR_CF)
                        .setKey(avatarId)
                        .setName(SIZE)
                        .execute()
                        .get();

        if (columnSize != null && columnSize.getValue() != null) {
            avatar.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(AVATAR_CF)
                        .setKey(avatarId)
                        .setName(CREATION_DATE)
                        .execute()
                        .get();

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

        return avatar;
    }
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
        Avatar avatar = avatarService.getAvatarById(avatarId);
        if (avatarId == null) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        } else {
            // ETag support
            response.setHeader(HEADER_ETAG, avatarId); // The attachmentId is unique and should not be modified
            String requestETag = request.getHeader(HEADER_IF_NONE_MATCH);
            if (requestETag != null && requestETag.equals(avatarId)) {
                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            } else {
                try {
                    byte[] fileContent = avatar.getContent();
                    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> uploadAvatar(
            @RequestParam("uploadFile") MultipartFile file) throws IOException {

        Avatar avatar = new Avatar();
        avatar.setContent(file.getBytes());
        avatar.setFilename(file.getOriginalFilename());
        avatar.setSize(file.getSize());
        avatar.setCreationDate(new Date());

        avatarService.createAvatar(avatar);

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

        log.info("Avatar url : {}/tatami/avatar/{}/{}", tatamiUrl, avatar.getAvatarId(), file.getOriginalFilename());

        uploadedFiles.add(uploadedFile);

        User user = authenticationService.getCurrentUser();
        user.setAvatar(avatar.getAvatarId());

        userRepository.updateUser(user);

        return uploadedFiles;
View Full Code Here

    @ResponseBody
    @Timed
    public void uploadAvatarIE(
            @RequestParam("uploadFile") MultipartFile file) throws IOException {

        Avatar avatar = new Avatar();
        avatar.setContent(file.getBytes());
        avatar.setFilename(file.getOriginalFilename());
        avatar.setSize(file.getSize());
        avatar.setCreationDate(new Date());

        avatarService.createAvatar(avatar);

        log.info("Avatar url : {}/tatami/avatar/{}/{}", tatamiUrl, avatar.getAvatarId(), file.getOriginalFilename());

        User user = authenticationService.getCurrentUser();
        user.setAvatar(avatar.getAvatarId());

        userRepository.updateUser(user);

    }
View Full Code Here

TOP

Related Classes of fr.ippon.tatami.domain.Avatar

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.