Ejemplo n.º 1
0
  /** Upload attachment file for issue */
  public void uploadFile() {
    String filename = JSFUtils.getRequestParameter("filename");
    String diskFileName =
        this.attachmentService.fileNameProcess(FilenameUtils.removeExtension(filename));
    diskFileName = this.attachmentService.replaceFile(filename, diskFileName);
    attachment = new Attachment();
    attachment.setFilename(filename);
    attachment.setDiskFilename(diskFileName);
    attachment.setContainerId(issue.getIssueId());
    attachment.setContainerType(Attachment.ISSUE_ATTACHMENT);
    // add files of Issue in user story for easy to handle.
    if (issue.getUserStory() != null) {
      attachment.setContainerId(issue.getUserStory().getUserStoryId());
      attachment.setContainerType(Attachment.USERSTORY_ATTACHMENT);
    }

    attachment.setTemp(false);
    attachment.setCreatedOn(new Date());
    attachment.setAuthor(utils.getLoggedInMember());
    attachmentService.save(attachment);
    Attachment newAttachment = attachmentService.findAttachmentById(attachment.getAttachmentId());

    if (attachmentNotAddList == null) {
      attachmentNotAddList = new ArrayList<Attachment>();
    }

    if (newAttachment.getContainerId() != null) {
      attachment.setTemp(false);
      attachmentService.moveAttachmentFile(attachment, projectId);
    } else {
      attachment.setTemp(true);
      attachmentNotAddList.add(newAttachment);
    }

    attachmentListByIssue = attachmentService.findAttachmentByIssue(issue);
    if (issue.getUserStory() != null) {
      attachmentListByIssue.addAll(
          attachmentService.findAttachmentByUserStory(issue.getUserStory()));
    }
  }