Package org.osforce.connect.entity.commons

Examples of org.osforce.connect.entity.commons.Attachment


    File targetFile = getTargetFile(attachment);
    FileUtils.writeByteArrayToFile(targetFile, attachment.getBytes());
  }
 
  public static Attachment parse(MultipartFile file) throws IOException {
    Attachment attachment = new Attachment();
    attachment.setContentType(file.getContentType());
    attachment.setFileName(file.getOriginalFilename());
    attachment.setSize(file.getSize());
    attachment.setBytes(file.getBytes());
    return attachment;
  }
View Full Code Here


  @RequestMapping(value="/form-action", method=RequestMethod.POST)
  @Permission(value={"profile-add", "profile-edit"}, userRequired=true)
  public @ResponseBody Object doFormAction(
      @RequestParam MultipartFile file,
      @RequestParam Long profileId) throws IOException {
    Attachment attachment = AttachmentUtil.parse(file);
    attachmentService.createAttachment(attachment);
    // write attachment content to local file
    AttachmentUtil.write(attachment);
    Profile profile = profileService.getProfile(profileId);
    Attachment logo = profile.getLogo();
    // delete logo
    if(logo!=null) {
      // delete from disk
      AttachmentUtil.delete(logo);
      // delete from database
      attachmentService.deleteAttachment(logo.getId());
    }
    profile.setLogo(attachment);
    profileService.updateProfile(profile);
    return Collections.singletonMap("id", profile.getId());
  }
View Full Code Here

      HttpServletResponse response) throws IOException {
    download(id, null, response);
  }
 
  public void download(Long targetId, String dimension,HttpServletResponse response) throws IOException {
    Attachment attachment = attachmentService.getAttachment(targetId);
    attachment.setDimension(dimension);
    // read attachment content from local file
    AttachmentUtil.read(attachment);
    // prepare download
    if(!attachment.getContentType().matches("image/.*")) {
      response.setContentType(attachment.getContentType());
      response.setContentLength(attachment.getSize().intValue());
      response.setHeader("Content-Disposition","attachment; filename=\"" + attachment.getFileName() +"\"");
    }
    response.getOutputStream().write(attachment.getBytes());
  }
View Full Code Here

      model.addAttribute(AttributeKeys.FEATURE_CODE_KEY_READABLE, ProjectFeature.FEATURE_GALLERY);
      return "page:/gallery/photo-form";
    }
    //
    if(file.getSize()>0) {
      Attachment attachment = AttachmentUtil.parse(file);
      attachmentService.createAttachment(attachment);
      AttachmentUtil.write(attachment);
      //
      if(photo.getRealFileId()!=null) {
        Attachment needDelete = attachmentService.getAttachment(photo.getRealFileId());
        AttachmentUtil.delete(needDelete);
        attachmentService.deleteAttachment(photo.getRealFileId());
      }
      photo.setRealFileId(attachment.getId());
    }
View Full Code Here

    if(file.getFolderId()!=null) {
      Folder folder = folderDao.get(file.getFolderId());
      file.setFolder(folder);
    }
    if(file.getRealFileId()!=null) {
      Attachment realFile = attachmentDao.get(file.getRealFileId());
      file.setRealFile(realFile);
    }
    Date now = new Date();
    file.setModified(now);
    if(file.getId()==null) {
View Full Code Here

      model.addAttribute(AttributeKeys.FEATURE_CODE_KEY_READABLE, ProjectFeature.FEATURE_DOCUMENT);
      return "page:/document/file-form";
    }
    //
    if(file.getSize() > 0) {
      Attachment attachment = AttachmentUtil.parse(file);
      attachmentService.createAttachment(attachment);
      AttachmentUtil.write(attachment);
      //
      if(fileItem.getRealFileId()!=null) {
        Attachment needDelete = attachmentService.getAttachment(fileItem.getRealFileId());
        AttachmentUtil.delete(needDelete);
        attachmentService.deleteAttachment(fileItem.getRealFileId());
      }
      fileItem.setRealFileId(attachment.getId());
    }
View Full Code Here

    if(profile.getProjectId()!=null) {
      Project project = projectDao.get(profile.getProjectId());
      profile.setProject(project);
    }
    if(profile.getLogoId()!=null) {
      Attachment logo = attachmentDao.get(profile.getLogoId());
      profile.setLogo(logo);
    }
    Date now = new Date();
    profile.setModified(now);
    if(profile.getId()==null) {
View Full Code Here

    if(photo.getAlbumId()!=null) {
      Album album = albumDao.get(photo.getAlbumId());
      photo.setAlbum(album);
    }
    if(photo.getRealFileId()!=null) {
      Attachment realFile = attachmentDao.get(photo.getRealFileId());
      photo.setRealFile(realFile);
    }
    Date now = new Date();
    photo.setModified(now);
    if(photo.getId()==null) {
View Full Code Here

TOP

Related Classes of org.osforce.connect.entity.commons.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.